7

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.

Patrick
  • 2,044
  • 1
  • 25
  • 44
jar
  • 2,646
  • 1
  • 22
  • 47
  • 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? – Daemon Painter Nov 16 '20 at 08:53
  • @DaemonPainter the short answer is that I am just trying to get this - https://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". – jar Nov 16 '20 at 09:25
  • 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. – Daemon Painter Nov 16 '20 at 10:06

1 Answers1

4

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.

Daemon Painter
  • 3,208
  • 3
  • 29
  • 44
  • Yeah, I feel stupid now. You are right. It worked once I created the remote branch. That `--head` thing confused me a lot. – jar Nov 16 '20 at 11:37
  • 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. – Daemon Painter Nov 16 '20 at 12:56