Support `forced` checkout of pull request. #132

slippycheeze opened this Issue Jan 24, 2012 · 4 comments

2 participants


I use hub checkout $pull_request_url to get at code in order to test it before merging, and hope to automate use of that in future. This works wonderfully the first time around, but has trouble if someone rewrites their branch with rebase or equivalent and then asks us to merge it again from the updated pull request.

The specific problem is that hub tries to create the target branch with checkout -b ..., and that fails if the target branch already exists.

I would love to support the equivalent of git checkout -f $branch for pull requests, so that I could forcibly end up on the current version of that pull, regardless of the branch existing or not.

GitHub member

If someone force-pushed to the remote branch, there's a more correct way to reset to the latest state:

$ git fetch
$ git reset --hard @{u}

However since git checkout already supports the -f flag, the fact that it's ignored here is a bug. I should forward all flags for checkout to the checkout command that happens internally. Good catch.


Ultimately, I don't care about the implementation, but it would be nice to have a robust "one command" mechanism to get to the current state of a pull request. I have been, in the interim, working around it by doing a manual checkout and hard reset when the wrapper failed.

(I deal with enough pull requests, as the primary part of my work, that I don't recall if I have done this before - I can't trivially preempt this ahead of time.)

@mislav mislav added a commit that closed this issue Jan 28, 2012
@mislav mislav improve `checkout` command
Now forwards flags to internal `checkout` command, resets the existing
local branch by default.

Closes #132
@mislav mislav closed this in 7e804aa Jan 28, 2012
GitHub member

With 7e804aa, hub checkout now resets the local branch by default. However if you need to pass additional flags like -f, they will be forwarded to the internal git checkout command.


@mislav awesome. Thanks, that makes this exactly match my expected workflow.

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