pull-request should create the remote branch if it doesn't already exist #165

jfirebaugh opened this Issue Apr 17, 2012 · 15 comments


None yet

10 participants


When the remote branch on your own repository doesn't exist, the current behavior of pull-request is confusing: it opens the editor with a stub message, and then if you fill out a message and continue, the submission fails with an opaque error message: "Error creating pull request: Unprocessable Entity (HTTP 422)".

A better error message like would help, but in this case, I think pull-request should just automatically push to a new remote branch before opening the pull request, since that's almost always what you want.

mislav commented Apr 23, 2012

pull-request already warns you about unpushed changes, AFAIK. I am reluctant to make some behavior automatic since this is not in the spirit of git. But I'll leave this open and think about it. I agree that most people would expect that they open a pull request with the contents of their local branch, and that they might push it.


It warns you about unpushed changes only if the remote branch already exists. If not, you get a much more confusing error message. I'd be okay with showing a warning in this case as well, so long as the -f (force) flag works.

mislav commented Apr 25, 2012

This definitely needs to be more user-friendly. I'll leave this open to think about this.

scribu commented Jul 7, 2012

+1 for this. It took me a while to figure out why I got these weird errors:

$ git pull-request -i 179 

Error creating pull request: Unprocessable Entity (HTTP 422)
field 'head_sha' is missing
field 'base_sha' is missing
base No commits between scribu:master and scribu:user-columns

Sure this isn't the spirit of git, but it is the spirit of hub, which is to do multiple git commands in a single command. Currently, you have to do two commands

git push github branchname
hub pull-request

Other hub commands are already shortcuts to multiple git commands (e.g., hub fetch). So I think it should automatically push. -f should only be required if the push is non-fast forward (same with git push). A nicer error message would be nice, but I would still be annoyed that it didn't just push for me in the first place.

mislav commented Feb 16, 2013

Agreed. pull-request could do the push for you.

The questions that you need to help me answer next are:

  1. To which remote does the new branch gets pushed to, if there are multiple ones?
  2. What if the branch was already pushed, but we have some more commits locally that weren't pushed?
  3. What if the working copy is dirty at the time of pull-request?

Ah, I guess there's no way for hub to know what your account is. Does anyone ever have more than one fork of a repo that they can push to? If so, that's a fourth question. I guess there's got to be a way to configure hub to tell it what your remote should be called. I personally always call my remote github. For some people, it will always be called origin. For others, they may call it after their username.

Can hub query what forks of a repo you have push access to?

To answer your other questions:

  1. I guess push them. You could also just ask.
  2. I would just do it anyway, maybe noting it to the user.
Peeja commented Feb 21, 2013

@asmeurer In my org, we have a main repo, and we PR from our own forks. We all apparently have push access to every fork in the network.

reidpr commented May 29, 2013

A comprehensible error message to the effect of "this branch either has no remote branch, or the remote branch is not up to date; try pushing" would go a long way here.

cluesque commented Aug 6, 2013

In my org we all share one repo, and cooperate with pull requests on branches. By convention we all use the remote name "origin" for that repo.

So my ideal would:

  • take the name of the branch from the local branch
  • default to the 'origin' remote, otherwise take an argument
  • create the branch if it doesn't exist, require -f if it exists but is stale (or prompt?)
  • (perhaps for bonus points) take an argument for what remote (other than 'origin') to send the pull request to
asmeurer commented Aug 6, 2013

But the more common use-case, esp. for open source, is to push to a fork, even if you have push access to the main repo. I always call mine "github". The hub convention would be to call it by your user name.

I definitely would want hub to default to pushing up to origin. Probably it should just ask for each repo, and save the result. Also allow a global config for people like me where it's always the same.

cabello commented Jan 21, 2015

Since issuing two commands might break people workflow, how about just improve the output a little bit?

$ hub pull-request
Error creating pull request: Unprocessable Entity (HTTP 422)
Missing field: "head_sha"
Missing field: "base_sha"
No commits between foo:master and foo:foobar
Did you forget to push the branch? 

yes the Missing field "head_sha" etc is pretty unhelpful internal leakage in this case where it might be fairly obvious what has gone wrong

I'm getting this error when trying to git pull-request from a repo that's on an organization I own, repo is not on my account. Consider this use case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment