How to make a Pull Request using the new github cli, to a remote repo without pushing a remote branch too?
Asked Answered
A

1

10

I am trying to figure out how to make a PR to my remote repository from a local branch (or even from local master/main branch). However, no matter what I do I get the following error:

Attempt from local main:

(master)$ gh pr create --title "Adding readme" --body "Testing pr from cli" --head armsp:feature

Creating pull request for armsp:feature into master in armsp/----

pull request create failed: GraphQL error: Head sha can't be blank, Base sha can't be blank, No commits between master and feature, Head ref must be a branch

Attempt from the local feature branch:

(feature)$ gh pr create --title "Adding readme" --body "Testing pr from cli" --head armsp:feature

Creating pull request for armsp:feature into master in armsp/----

pull request create failed: GraphQL error: Head sha can't be blank, Base sha can't be blank, No commits between master and feature, Head ref must be a branch

The general steps for the whole situation is -

  1. Commit and push some files from local main to remote main
  2. Make a new local branch feature, edit something, commit
  3. PR
    1. Use --head arguement of gh from local branch to make PR directly to remote without making the same remote branch
    2. Use --head arguement of gh from the local master without making a remote branch

I have seen a couple of issues on the github cli repo and they seem to have been fixed in a release, but it unfortunately still doesn't work for me.

My gh version

$ gh version
gh version 1.2.1 (2020-11-11)

NOTE: It is IMPERATIVE that I make the PR completely via terminal/cli.

Arnaldo answered 16/11, 2020 at 5:34 Comment(4)
pull request from remote to local to what end? A pull request is a request for the remote GitHub workflow to tell upstream/manager "hey, my code is ready, please take it". You are working on your local machine, you download your code. Could you please help understand this better?Zacharia
@DaemonPainter the short answer is that I am just trying to get this - cli.github.com/manual/gh_pr_create - to work. What I actually meant is, my code is ready - on my local branch - to be merged to the remote "main" / "master".Arnaldo
The first line states "When the current branch isn't fully pushed to a git remote, a prompt will ask where to push the branch and offer an option to fork the base repository. Use '--head' to explicitly skip any forking or pushing behavior." (emph. mine). Note fully, as implicitly contrasting with partially pushed. There must be something on the remote to create a Pull Request from. Unless you expect your remote to fetch/pull from your locale.Zacharia
@DaemonPainter that was what I was expecting - that github cli could take local changes (diff from master to origin/master) and basically create PR without creating and pushing unnecessary branches (just for the sake of PR creation).Unfeigned
Z
5

You can't, you should at least create a branch on the remote first.

After the mandatory introduction on what is a Pull Request in Git vs GitHub, I'll quote the following:

Pull requests let you tell others about changes you've pushed to a branch in a repository on GitHub. Once a pull request is opened, you can discuss and review the potential changes with collaborators and add follow-up commits before your changes are merged into the base branch. source.

GitHub PR expect some code on the remote GitHub server, at least a branch.

Create a pull request to propose and collaborate on changes to a repository. These changes are proposed in a branch, which ensures that the default branch only contains finished and approved work. source.

You expect to open a Pull Request on remote for a branch that doesn't exists. Create the branch first, then try again. Remember that you won't be able to have the remote automatically fetching or pulling content from your local to the remote, so in the end you'll have to push it.

Zacharia answered 16/11, 2020 at 10:10 Comment(3)
Yeah, I feel stupid now. You are right. It worked once I created the remote branch. That --head thing confused me a lot.Arnaldo
Don't, it is a truly valid question and I feel like the page you linked on gh function is too much vague on the subject.Zacharia
+1 it is trully valid question, I think github cli could be able to do PR without requiring you to have a remote branch, but just taking your local changes.Unfeigned

© 2022 - 2024 — McMap. All rights reserved.