Hub: Pushing changes to a pull request URL?

Created on 24 Feb 2015  ·  8Comments  ·  Source: github/hub

You can check out a PR using:

$ hub checkout https://github.com/defunkt/hub/pull/73

When you make a change and commit that change, what do you do to push it to the PR?

Because just doing "git push" gives a message like this:

fatal: The upstream branch of your current branch does not match
the name of your current branch. To push to the upstream branch
on the remote, use

git push myproject HEAD:bar-baz

To push to the branch of the same name on the remote, use

git push myproject foo-bar-baz
feature pull-request

Most helpful comment

@tlvince My idea for hub checkout <PR-URL> is that it should use the API to determine the context of the branch that you're checking out. If it's from the same repo, or from a fork that you have push access to, it will checkout a new branch and set up upstream tracking so git push should work without problems. If it's a fork that you don't have write access to (most open source forks), the branch will be checked out like right now: with auto-generated name, and without upstream configuration. It makes no sense to git push a branch from a repo you don't have write access to, anyway.

Let me know if that makes sense.

All 8 comments

Yes, you will probably not be able to use just git push for a branch created this way. You need to tell explicitly where you want to push:

git push origin HEAD:my-branch-name

I know that this could be friendlier. Is the PR that you're checking out originating from the same repo or from a fork? If it's same-repo, then we could ensure that the local branch you're checking out to is the same name as the remote branch which is the head for the PR. Then, git push would simply work because the branches have matching names (see push.default section of git help config)

It's the same repo, ensuring that that the local branch is the same name as the remote branch would be an awesome improvement.

Is there a way to hub checkout a PR url without changing the name of the branch?

No, hub still auto-generates the name of the checked-out branch so this is still not push-friendly.

I'll try to get this fixed for the next release so that same-repo PRs are easier to handle.

Sorry for the "+1 comment", but this would be a very welcome addition.

My usual workflow is something like:

git push --tags --set-upstream origin branch

On subsequent pushes, simply git push will do.

Checking out a PR with hub creates a branch in the form [org]-[branch], so I'm forced to use something like following each time I want to update the PR:

git push [org]-[branch]:[branch]

Perhaps if origin contains org ([email protected]:[org]), the [org]- prefix can be omitted?

@tlvince My idea for hub checkout <PR-URL> is that it should use the API to determine the context of the branch that you're checking out. If it's from the same repo, or from a fork that you have push access to, it will checkout a new branch and set up upstream tracking so git push should work without problems. If it's a fork that you don't have write access to (most open source forks), the branch will be checked out like right now: with auto-generated name, and without upstream configuration. It makes no sense to git push a branch from a repo you don't have write access to, anyway.

Let me know if that makes sense.

Now that the GitHub default for PRs is to allow pushes from upstream maintainers I bet a lot more people than before now want “it just works” for pushes from hub checkout <PR-URL> branches.

Workaround for now:

git config --global push.default upstream
git config --global [email protected]:.pushInsteadOf git://github.com/

With those settings a git push (with no args needed) in a hub checkout <PR-URL> branch will work.

Was this page helpful?
0 / 5 - 0 ratings