Instantly share code, notes, and snippets.

Embed
What would you like to do?
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git
	fetch = +refs/pull/*/head:refs/remotes/origin/pr/*

Now fetch all the pull requests:

$ git fetch origin
From github.com:joyent/node
 * [new ref]         refs/pull/1000/head -> origin/pr/1000
 * [new ref]         refs/pull/1002/head -> origin/pr/1002
 * [new ref]         refs/pull/1004/head -> origin/pr/1004
 * [new ref]         refs/pull/1009/head -> origin/pr/1009
...

To check out a particular pull request:

$ git checkout pr/999
Branch pr/999 set up to track remote branch pr/999 from origin.
Switched to a new branch 'pr/999'
@DTrejo

This comment has been minimized.

Show comment
Hide comment
@DTrejo

DTrejo commented Aug 13, 2012

LOVELY.

@chilts

This comment has been minimized.

Show comment
Hide comment
@chilts

chilts Aug 13, 2012

Hey cool. Didn't know you could do that! :) Thanks.

chilts commented Aug 13, 2012

Hey cool. Didn't know you could do that! :) Thanks.

@sminnee

This comment has been minimized.

Show comment
Hide comment
@sminnee

sminnee commented Aug 13, 2012

GENIUS!

@naholyr

This comment has been minimized.

Show comment
Hide comment
@naholyr

naholyr Aug 14, 2012

So much love \o/

naholyr commented Aug 14, 2012

So much love \o/

@AlekSi

This comment has been minimized.

Show comment
Hide comment
@AlekSi

AlekSi commented Aug 14, 2012

⭐️

@cordoval

This comment has been minimized.

Show comment
Hide comment
@cordoval

cordoval commented Aug 14, 2012

thanks!

@johnnagro

This comment has been minimized.

Show comment
Hide comment
@johnnagro

johnnagro commented Aug 15, 2012

⛵️

@mikaelkaron

This comment has been minimized.

Show comment
Hide comment
@mikaelkaron

mikaelkaron commented Aug 16, 2012

awesome!

@cldwalker

This comment has been minimized.

Show comment
Hide comment
@cldwalker

cldwalker Aug 25, 2012

Nice! I dropped this in my rc file to make this process easy:
function pullify() {
git config --add remote.origin.fetch '+refs/pull//head:refs/remotes/origin/pr/'
}

cldwalker commented Aug 25, 2012

Nice! I dropped this in my rc file to make this process easy:
function pullify() {
git config --add remote.origin.fetch '+refs/pull//head:refs/remotes/origin/pr/'
}

@piscisaureus

This comment has been minimized.

Show comment
Hide comment
@piscisaureus

piscisaureus Aug 27, 2012

@cldwalker

Thanks. I just realized that with this trick you can enable it for all your repos at once :-)

git config --global --add remote.origin.fetch "+refs/pull/*/head:refs/remotes/origin/pr/*"

Owner

piscisaureus commented Aug 27, 2012

@cldwalker

Thanks. I just realized that with this trick you can enable it for all your repos at once :-)

git config --global --add remote.origin.fetch "+refs/pull/*/head:refs/remotes/origin/pr/*"

@andhapp

This comment has been minimized.

Show comment
Hide comment
@andhapp

andhapp Sep 27, 2012

Just for fetching only one pull request. Handy, if you're hacking on something.

  git fetch origin pull/7324/head:pr-7324

origin points to the remote server.
pull/7324/head is the remote pull request.
pr-7324 is the local pull-request branch.

andhapp commented Sep 27, 2012

Just for fetching only one pull request. Handy, if you're hacking on something.

  git fetch origin pull/7324/head:pr-7324

origin points to the remote server.
pull/7324/head is the remote pull request.
pr-7324 is the local pull-request branch.

@TrevorBurnham

This comment has been minimized.

Show comment
Hide comment
@TrevorBurnham

TrevorBurnham Nov 26, 2012

@piscisaureus The global config trick has an unfortunate side-effect. See http://stackoverflow.com/questions/13572191/cannot-remove-remote-origin/. Might be worth the tradeoff, but it's worth being aware of.

TrevorBurnham commented Nov 26, 2012

@piscisaureus The global config trick has an unfortunate side-effect. See http://stackoverflow.com/questions/13572191/cannot-remove-remote-origin/. Might be worth the tradeoff, but it's worth being aware of.

@havvg

This comment has been minimized.

Show comment
Hide comment
@havvg

havvg Nov 27, 2012

Your refspec is wrong, isn't it?

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = git@github.com:joyent/node.git
    fetch = +refs/pull/*/head:refs/remotes/origin/pr/*

In case you retrieve a branch named pr/3 from the origin fetched based on your first refspec +refs/heads/*:refs/remotes/origin/* and there is a third pull request, it would conflict. I never tried it, but that's why I got fetch = +refs/pull/*/head:refs/gh-pull/remotes/origin/* as refspec, which is not conflicting with anything of git.

On a side note, when building scripts imitating the "merge"-button of github, you can make use of fetch = +refs/pull/*/merge:refs/gh-merge/remotes/origin/* which point to the merge commit of the respective pull request.

havvg commented Nov 27, 2012

Your refspec is wrong, isn't it?

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = git@github.com:joyent/node.git
    fetch = +refs/pull/*/head:refs/remotes/origin/pr/*

In case you retrieve a branch named pr/3 from the origin fetched based on your first refspec +refs/heads/*:refs/remotes/origin/* and there is a third pull request, it would conflict. I never tried it, but that's why I got fetch = +refs/pull/*/head:refs/gh-pull/remotes/origin/* as refspec, which is not conflicting with anything of git.

On a side note, when building scripts imitating the "merge"-button of github, you can make use of fetch = +refs/pull/*/merge:refs/gh-merge/remotes/origin/* which point to the merge commit of the respective pull request.

@tomjenkinson

This comment has been minimized.

Show comment
Hide comment
@tomjenkinson

tomjenkinson Dec 20, 2012

Anyone managed to work out how to actually remove the pull ref, for example:
git push origin :pr/1
doesn't seem to work

tomjenkinson commented Dec 20, 2012

Anyone managed to work out how to actually remove the pull ref, for example:
git push origin :pr/1
doesn't seem to work

@pcreux

This comment has been minimized.

Show comment
Hide comment
@pcreux

pcreux Jan 22, 2013

You can also use https://github.com/defunkt/hub and run git checkout https://github.com/defunkt/hub/pull/73

pcreux commented Jan 22, 2013

You can also use https://github.com/defunkt/hub and run git checkout https://github.com/defunkt/hub/pull/73

@arthurnn

This comment has been minimized.

Show comment
Hide comment
@arthurnn

arthurnn Feb 2, 2013

Any reason for, when I do
git fetch origin --prune
it creates the pr local branches and it deletes them right after?

output:

 * [new ref]         refs/pull/1/head -> origin/pr/1
 * [new ref]         refs/pull/2/head -> origin/pr/2
 x [deleted]         (none)     -> origin/pr/1
 x [deleted]         (none)     -> origin/pr/2

arthurnn commented Feb 2, 2013

Any reason for, when I do
git fetch origin --prune
it creates the pr local branches and it deletes them right after?

output:

 * [new ref]         refs/pull/1/head -> origin/pr/1
 * [new ref]         refs/pull/2/head -> origin/pr/2
 x [deleted]         (none)     -> origin/pr/1
 x [deleted]         (none)     -> origin/pr/2
@jimi-c

This comment has been minimized.

Show comment
Hide comment
@jimi-c

jimi-c Feb 9, 2013

@tomjenkinson did you ever figure out a solution to deleting them remotely, or to at least ignore those that are closed?

jimi-c commented Feb 9, 2013

@tomjenkinson did you ever figure out a solution to deleting them remotely, or to at least ignore those that are closed?

@jasoncodes

This comment has been minimized.

Show comment
Hide comment
@jasoncodes

jasoncodes Feb 19, 2013

@arthurnn The fetch line for pull requests needs to be before the one for heads. I wrote a small shell function to do this.

jasoncodes commented Feb 19, 2013

@arthurnn The fetch line for pull requests needs to be before the one for heads. I wrote a small shell function to do this.

@robinsmidsrod

This comment has been minimized.

Show comment
Hide comment
@robinsmidsrod

robinsmidsrod Mar 6, 2013

I just wanted to chime in and tell you about a tool I put together to work with pull requests from the command line.

I know it's been done before, but I wanted to take a slightly different approach.

It's here: http://github.com/robinsmidsrod/App-GitHubPullRequest

robinsmidsrod commented Mar 6, 2013

I just wanted to chime in and tell you about a tool I put together to work with pull requests from the command line.

I know it's been done before, but I wanted to take a slightly different approach.

It's here: http://github.com/robinsmidsrod/App-GitHubPullRequest

@sthulb

This comment has been minimized.

Show comment
Hide comment
@sthulb

sthulb commented Mar 22, 2013

👍

@hlysig

This comment has been minimized.

Show comment
Hide comment
@hlysig

hlysig Mar 25, 2013

awesome!

hlysig commented Mar 25, 2013

awesome!

@ypandit

This comment has been minimized.

Show comment
Hide comment
@ypandit

ypandit commented Mar 25, 2013

👍

@Darep

This comment has been minimized.

Show comment
Hide comment
@Darep

Darep commented Mar 25, 2013

❤️

@iqbalhasnan

This comment has been minimized.

Show comment
Hide comment
@iqbalhasnan

iqbalhasnan commented Mar 25, 2013

@joelmccracken

This comment has been minimized.

Show comment
Hide comment
@joelmccracken

joelmccracken Mar 25, 2013

The way I normally do this is just to add the other user as a remote:

git remote add other_user other_user_repo_url
git fetch other_user
git checkout -b other_user_branch other_user/branch

Nice, though!

joelmccracken commented Mar 25, 2013

The way I normally do this is just to add the other user as a remote:

git remote add other_user other_user_repo_url
git fetch other_user
git checkout -b other_user_branch other_user/branch

Nice, though!

@crucialfelix

This comment has been minimized.

Show comment
Hide comment
@crucialfelix

crucialfelix Mar 25, 2013

ooh, I've been trying to figure this one out forever ! I strongly dislike just reading and clicking "merge this" without testing.

crucialfelix commented Mar 25, 2013

ooh, I've been trying to figure this one out forever ! I strongly dislike just reading and clicking "merge this" without testing.

@chadwhitacre

This comment has been minimized.

Show comment
Hide comment
@chadwhitacre

chadwhitacre commented Mar 25, 2013

🚀

@JohnMcLear

This comment has been minimized.

Show comment
Hide comment
@JohnMcLear

JohnMcLear commented Mar 25, 2013

Thank you

@mwhite

This comment has been minimized.

Show comment
Hide comment
@mwhite

mwhite Mar 25, 2013

You can also try https://github.com/splitbrain/git-pull-request which shows you a list of pull requests.

mwhite commented Mar 25, 2013

You can also try https://github.com/splitbrain/git-pull-request which shows you a list of pull requests.

@chadwhitacre

This comment has been minimized.

Show comment
Hide comment
@chadwhitacre

chadwhitacre Mar 25, 2013

For the record, pushing a locally-merged PR closed it in the GitHub UI.

chadwhitacre commented Mar 25, 2013

For the record, pushing a locally-merged PR closed it in the GitHub UI.

@chadwhitacre

This comment has been minimized.

Show comment
Hide comment
@chadwhitacre

chadwhitacre Mar 25, 2013

I get an error trying to set up the branch as a tracking branch:

$ git checkout pr/785
error: Not tracking: ambiguous information for ref refs/remotes/origin/pr/785
Switched to a new branch 'pr/785'
$

Indications are that it's because there are too many such branches?

chadwhitacre commented Mar 25, 2013

I get an error trying to set up the branch as a tracking branch:

$ git checkout pr/785
error: Not tracking: ambiguous information for ref refs/remotes/origin/pr/785
Switched to a new branch 'pr/785'
$

Indications are that it's because there are too many such branches?

@chadwhitacre

This comment has been minimized.

Show comment
Hide comment
@chadwhitacre

chadwhitacre Mar 25, 2013

And also for the record, a fast-forward merge doesn't seem to close the PR in GitHub. That is, I rebased master onto pr/785, then merged pr/785 to master, then pushed, and the PR is still open.

chadwhitacre commented Mar 25, 2013

And also for the record, a fast-forward merge doesn't seem to close the PR in GitHub. That is, I rebased master onto pr/785, then merged pr/785 to master, then pushed, and the PR is still open.

@chadwhitacre

This comment has been minimized.

Show comment
Hide comment
@chadwhitacre

chadwhitacre Mar 25, 2013

I hypothesize that rebasing meant that the original commit hash was lost, and GitHub looks at commit hashes to determine whether a PR is closed.

chadwhitacre commented Mar 25, 2013

I hypothesize that rebasing meant that the original commit hash was lost, and GitHub looks at commit hashes to determine whether a PR is closed.

@chadwhitacre

This comment has been minimized.

Show comment
Hide comment
@chadwhitacre

chadwhitacre Mar 25, 2013

I wonder if my broken tracking branch affects this as well?

chadwhitacre commented Mar 25, 2013

I wonder if my broken tracking branch affects this as well?

@treyhunner

This comment has been minimized.

Show comment
Hide comment
@treyhunner

treyhunner Mar 25, 2013

@whit537 I think you're right about rebase being the issue. Github looks only for the hashes in the original PR commits. A fast-forward vs. non-fast-forward shouldn't matter, but if a rebase changes the hashes it won't work.

treyhunner commented Mar 25, 2013

@whit537 I think you're right about rebase being the issue. Github looks only for the hashes in the original PR commits. A fast-forward vs. non-fast-forward shouldn't matter, but if a rebase changes the hashes it won't work.

@chadwhitacre

This comment has been minimized.

Show comment
Hide comment
@chadwhitacre

chadwhitacre Mar 25, 2013

Per: http://mislav.uniqpath.com/2013/02/merge-vs-rebase/

It seems that git merge --no-ff pr/785 and git cherry-pick pr/785 might be good parts of a workflow that doesn't confuse GitHub.

chadwhitacre commented Mar 25, 2013

Per: http://mislav.uniqpath.com/2013/02/merge-vs-rebase/

It seems that git merge --no-ff pr/785 and git cherry-pick pr/785 might be good parts of a workflow that doesn't confuse GitHub.

@chadwhitacre

This comment has been minimized.

Show comment
Hide comment
@chadwhitacre

chadwhitacre Mar 25, 2013

@treyhunner Ah, okay, thanks. :)

chadwhitacre commented Mar 25, 2013

@treyhunner Ah, okay, thanks. :)

@chadwhitacre

This comment has been minimized.

Show comment
Hide comment
@chadwhitacre

chadwhitacre Mar 25, 2013

fetch = +refs/pull/*/head:refs/remotes/origin/pr/*

So if I'm reading this right, it means that GitHub keeps pull requests in the pull namespace, ya?

chadwhitacre commented Mar 25, 2013

fetch = +refs/pull/*/head:refs/remotes/origin/pr/*

So if I'm reading this right, it means that GitHub keeps pull requests in the pull namespace, ya?

@chadwhitacre

This comment has been minimized.

Show comment
Hide comment
@chadwhitacre

chadwhitacre Mar 25, 2013

I get the same error message trying to fix up a tracking branch after the fact:

$ git branch --set-upstream-to=origin/pr/782
error: Not tracking: ambiguous information for ref refs/remotes/origin/pr/782
$

chadwhitacre commented Mar 25, 2013

I get the same error message trying to fix up a tracking branch after the fact:

$ git branch --set-upstream-to=origin/pr/782
error: Not tracking: ambiguous information for ref refs/remotes/origin/pr/782
$
@jverkoey

This comment has been minimized.

Show comment
Hide comment
@jverkoey

jverkoey Mar 25, 2013

Hellz yeah, thanks!

jverkoey commented Mar 25, 2013

Hellz yeah, thanks!

@chadwhitacre

This comment has been minimized.

Show comment
Hide comment
@chadwhitacre

chadwhitacre Mar 25, 2013

Here's fetch:

$ git fetch
From github.com:gittip/www.gittip.com
 * [new ref]         refs/pull/100/head -> origin/pr/100
 * [new ref]         refs/pull/105/head -> origin/pr/105
 * [new ref]         refs/pull/117/head -> origin/pr/117
 * [new ref]         refs/pull/137/head -> origin/pr/137
[...]
 * [new ref]         refs/pull/782/head -> origin/pr/782
 * [new ref]         refs/pull/785/head -> origin/pr/785
 * [new ref]         refs/pull/788/head -> origin/pr/788
 * [new ref]         refs/pull/790/head -> origin/pr/790

And then:

$ git remote show origin
* remote origin
  Fetch URL: git@github.com:gittip/www.gittip.com.git
  Push  URL: git@github.com:gittip/www.gittip.com.git
  HEAD branch: master
  Remote branches:
    master                     tracked
    refs/pull/100/head         tracked
    refs/pull/105/head         tracked
    refs/pull/117/head         tracked
    refs/pull/137/head         tracked
[...]
    refs/pull/782/head         tracked
    refs/pull/785/head         tracked
    refs/pull/788/head         tracked
    refs/pull/790/head         tracked
    refs/remotes/origin/pr/100 stale (use 'git remote prune' to remove)
    refs/remotes/origin/pr/105 stale (use 'git remote prune' to remove)
    refs/remotes/origin/pr/117 stale (use 'git remote prune' to remove)
    refs/remotes/origin/pr/137 stale (use 'git remote prune' to remove)
[...]
    refs/remotes/origin/pr/782 stale (use 'git remote prune' to remove)
    refs/remotes/origin/pr/785 stale (use 'git remote prune' to remove)
    refs/remotes/origin/pr/788 stale (use 'git remote prune' to remove)
    refs/remotes/origin/pr/790 stale (use 'git remote prune' to remove)
  Local branches configured for 'git pull':
    master   merges with remote master
  Local refs configured for 'git push':
    master            pushes to master            (up to date)

And then:

$ git remote prune origin
Pruning origin
URL: git@github.com:gittip/www.gittip.com.git
 * [pruned] origin/pr/100
 * [pruned] origin/pr/105
 * [pruned] origin/pr/117
 * [pruned] origin/pr/137
[...]
 * [pruned] origin/pr/782
 * [pruned] origin/pr/785
 * [pruned] origin/pr/788
 * [pruned] origin/pr/790

Bringing me back to:

* remote origin
  Fetch URL: git@github.com:gittip/www.gittip.com.git
  Push  URL: git@github.com:gittip/www.gittip.com.git
  HEAD branch: master
  Remote branches:
    master             tracked
    refs/pull/100/head new (next fetch will store in remotes/origin)
    refs/pull/105/head new (next fetch will store in remotes/origin)
    refs/pull/117/head new (next fetch will store in remotes/origin)
    refs/pull/137/head new (next fetch will store in remotes/origin)
[...]
    refs/pull/782/head new (next fetch will store in remotes/origin)
    refs/pull/785/head new (next fetch will store in remotes/origin)
    refs/pull/788/head new (next fetch will store in remotes/origin)
    refs/pull/790/head new (next fetch will store in remotes/origin)
    rubygems           tracked
  Local branches configured for 'git pull':
    master   merges with remote master
  Local refs configured for 'git push':
    master            pushes to master            (up to date)

chadwhitacre commented Mar 25, 2013

Here's fetch:

$ git fetch
From github.com:gittip/www.gittip.com
 * [new ref]         refs/pull/100/head -> origin/pr/100
 * [new ref]         refs/pull/105/head -> origin/pr/105
 * [new ref]         refs/pull/117/head -> origin/pr/117
 * [new ref]         refs/pull/137/head -> origin/pr/137
[...]
 * [new ref]         refs/pull/782/head -> origin/pr/782
 * [new ref]         refs/pull/785/head -> origin/pr/785
 * [new ref]         refs/pull/788/head -> origin/pr/788
 * [new ref]         refs/pull/790/head -> origin/pr/790

And then:

$ git remote show origin
* remote origin
  Fetch URL: git@github.com:gittip/www.gittip.com.git
  Push  URL: git@github.com:gittip/www.gittip.com.git
  HEAD branch: master
  Remote branches:
    master                     tracked
    refs/pull/100/head         tracked
    refs/pull/105/head         tracked
    refs/pull/117/head         tracked
    refs/pull/137/head         tracked
[...]
    refs/pull/782/head         tracked
    refs/pull/785/head         tracked
    refs/pull/788/head         tracked
    refs/pull/790/head         tracked
    refs/remotes/origin/pr/100 stale (use 'git remote prune' to remove)
    refs/remotes/origin/pr/105 stale (use 'git remote prune' to remove)
    refs/remotes/origin/pr/117 stale (use 'git remote prune' to remove)
    refs/remotes/origin/pr/137 stale (use 'git remote prune' to remove)
[...]
    refs/remotes/origin/pr/782 stale (use 'git remote prune' to remove)
    refs/remotes/origin/pr/785 stale (use 'git remote prune' to remove)
    refs/remotes/origin/pr/788 stale (use 'git remote prune' to remove)
    refs/remotes/origin/pr/790 stale (use 'git remote prune' to remove)
  Local branches configured for 'git pull':
    master   merges with remote master
  Local refs configured for 'git push':
    master            pushes to master            (up to date)

And then:

$ git remote prune origin
Pruning origin
URL: git@github.com:gittip/www.gittip.com.git
 * [pruned] origin/pr/100
 * [pruned] origin/pr/105
 * [pruned] origin/pr/117
 * [pruned] origin/pr/137
[...]
 * [pruned] origin/pr/782
 * [pruned] origin/pr/785
 * [pruned] origin/pr/788
 * [pruned] origin/pr/790

Bringing me back to:

* remote origin
  Fetch URL: git@github.com:gittip/www.gittip.com.git
  Push  URL: git@github.com:gittip/www.gittip.com.git
  HEAD branch: master
  Remote branches:
    master             tracked
    refs/pull/100/head new (next fetch will store in remotes/origin)
    refs/pull/105/head new (next fetch will store in remotes/origin)
    refs/pull/117/head new (next fetch will store in remotes/origin)
    refs/pull/137/head new (next fetch will store in remotes/origin)
[...]
    refs/pull/782/head new (next fetch will store in remotes/origin)
    refs/pull/785/head new (next fetch will store in remotes/origin)
    refs/pull/788/head new (next fetch will store in remotes/origin)
    refs/pull/790/head new (next fetch will store in remotes/origin)
    rubygems           tracked
  Local branches configured for 'git pull':
    master   merges with remote master
  Local refs configured for 'git push':
    master            pushes to master            (up to date)
@chadwhitacre

This comment has been minimized.

Show comment
Hide comment
@chadwhitacre

chadwhitacre Mar 25, 2013

$ git --version
git version 1.8.1.3
$

chadwhitacre commented Mar 25, 2013

$ git --version
git version 1.8.1.3
$
@chadwhitacre

This comment has been minimized.

Show comment
Hide comment
@chadwhitacre

chadwhitacre Mar 25, 2013

Got it! The heroku remote in my .git/config conflicts. Let's see how to configure for both ...

chadwhitacre commented Mar 25, 2013

Got it! The heroku remote in my .git/config conflicts. Let's see how to configure for both ...

@chadwhitacre

This comment has been minimized.

Show comment
Hide comment
@chadwhitacre

chadwhitacre Mar 25, 2013

Well, next thing:

$ git branch
  master
* pull/782
$
$ git pull
Your configuration specifies to merge with the ref 'pull/782'
from the remote, but no such ref was fetched.
$

chadwhitacre commented Mar 25, 2013

Well, next thing:

$ git branch
  master
* pull/782
$
$ git pull
Your configuration specifies to merge with the ref 'pull/782'
from the remote, but no such ref was fetched.
$
@chadwhitacre

This comment has been minimized.

Show comment
Hide comment
@chadwhitacre

chadwhitacre Mar 25, 2013

@jasoncodes's tip above about the order of the fetch refspecs takes the stale output out of git remote show origin.

chadwhitacre commented Mar 25, 2013

@jasoncodes's tip above about the order of the fetch refspecs takes the stale output out of git remote show origin.

@chadwhitacre

This comment has been minimized.

Show comment
Hide comment
@chadwhitacre

chadwhitacre Mar 25, 2013

I fixed the heroku conflict by removing the fetch key in the [heroku] section of .git/config. Now it just looks like:

[remote "heroku"]                                                                             
    url = git@heroku.com:appname.git

I can still push to it just fine.

chadwhitacre commented Mar 25, 2013

I fixed the heroku conflict by removing the fetch key in the [heroku] section of .git/config. Now it just looks like:

[remote "heroku"]                                                                             
    url = git@heroku.com:appname.git

I can still push to it just fine.

@dvessel

This comment has been minimized.

Show comment
Hide comment
@dvessel

dvessel Mar 25, 2013

This is awesome!

Is it possible to filter for pull requests against a specific branch? thx!

::edit::

Never mind, doesn't look possible without it getting overly complicated. I wouldn't have gotten much out of it anyway.

dvessel commented Mar 25, 2013

This is awesome!

Is it possible to filter for pull requests against a specific branch? thx!

::edit::

Never mind, doesn't look possible without it getting overly complicated. I wouldn't have gotten much out of it anyway.

@jfairley

This comment has been minimized.

Show comment
Hide comment
@jfairley

jfairley commented Mar 26, 2013

👍

@marcelklehr

This comment has been minimized.

Show comment
Hide comment
@marcelklehr

marcelklehr commented Mar 26, 2013

awesome! :)

@moltar

This comment has been minimized.

Show comment
Hide comment
@moltar

moltar Apr 1, 2013

Dope!! Thanks for the tip.

moltar commented Apr 1, 2013

Dope!! Thanks for the tip.

@pferreir

This comment has been minimized.

Show comment
Hide comment
@pferreir

pferreir Apr 2, 2013

I cannot properly express all the love that this small piece of text musters in me. You have my gratitude.

pferreir commented Apr 2, 2013

I cannot properly express all the love that this small piece of text musters in me. You have my gratitude.

@superbrothers

This comment has been minimized.

Show comment
Hide comment
@superbrothers

superbrothers commented Apr 12, 2013

👍

@gnarf

This comment has been minimized.

Show comment
Hide comment
@gnarf

gnarf Apr 17, 2013

You can create an alias to pull single pulls:

In your global .gitconfig:

[alias]
 pr = "!f() { git fetch origin refs/pull/$1/head:pr/$1; } ; f"

of course this always assumes origin because thats all I ever use for upstream when I'm a maintainer, but you can customize that part too if you want, relatively trivial

gnarf commented Apr 17, 2013

You can create an alias to pull single pulls:

In your global .gitconfig:

[alias]
 pr = "!f() { git fetch origin refs/pull/$1/head:pr/$1; } ; f"

of course this always assumes origin because thats all I ever use for upstream when I'm a maintainer, but you can customize that part too if you want, relatively trivial

@rue

This comment has been minimized.

Show comment
Hide comment
@rue

rue Apr 19, 2013

This is the best thing ever.

rue commented Apr 19, 2013

This is the best thing ever.

@sickill

This comment has been minimized.

Show comment
Hide comment
@sickill

sickill Apr 21, 2013

I'm trying to figure out what's the value of this? Since each PR is attached to a branch you can just checkout the branch, right?

sickill commented Apr 21, 2013

I'm trying to figure out what's the value of this? Since each PR is attached to a branch you can just checkout the branch, right?

@stubb

This comment has been minimized.

Show comment
Hide comment
@stubb

stubb May 2, 2013

@sickill not if someone forks your repo and works within this repo

stubb commented May 2, 2013

@sickill not if someone forks your repo and works within this repo

@istro

This comment has been minimized.

Show comment
Hide comment
@istro

istro May 3, 2013

Thank you @piscisaureus for the Gist!
However, for my purposes - @gnarf37 - your solution is more concise :-)

istro commented May 3, 2013

Thank you @piscisaureus for the Gist!
However, for my purposes - @gnarf37 - your solution is more concise :-)

@franciscojunior

This comment has been minimized.

Show comment
Hide comment
@franciscojunior

franciscojunior May 20, 2013

Today when I did git pull I got a lot of

 * [new ref]

But I didn't change anything in my .git/config. I thought those new refs would only be pulled if I added the line

fetch = +refs/pull/*/head:refs/remotes/origin/pr/*

Is my understanding correct or am I missing something? Thanks in advance for any information.

franciscojunior commented May 20, 2013

Today when I did git pull I got a lot of

 * [new ref]

But I didn't change anything in my .git/config. I thought those new refs would only be pulled if I added the line

fetch = +refs/pull/*/head:refs/remotes/origin/pr/*

Is my understanding correct or am I missing something? Thanks in advance for any information.

@obusher

This comment has been minimized.

Show comment
Hide comment
@obusher

obusher commented May 22, 2013

img

@LocutusOfBorg

This comment has been minimized.

Show comment
Hide comment
@LocutusOfBorg

LocutusOfBorg commented May 27, 2013

Awesome!

@HBehrens

This comment has been minimized.

Show comment
Hide comment
@HBehrens

HBehrens Jul 2, 2013

Great, thanks :)

HBehrens commented Jul 2, 2013

Great, thanks :)

@gauteh

This comment has been minimized.

Show comment
Hide comment
@gauteh

gauteh Jul 22, 2013

Modification of @cldwalker suggestion, ~/.gitconfig:

[alias]
pullify = config --add remote.origin.fetch '+refs/pull/*/head:refs/remotes/origin/pr/*'

or for arbitrary remotes use $1 for 'origin'.

gauteh commented Jul 22, 2013

Modification of @cldwalker suggestion, ~/.gitconfig:

[alias]
pullify = config --add remote.origin.fetch '+refs/pull/*/head:refs/remotes/origin/pr/*'

or for arbitrary remotes use $1 for 'origin'.

@coderberry

This comment has been minimized.

Show comment
Hide comment
@coderberry

coderberry commented Aug 9, 2013

Thanks!

@domenkozar

This comment has been minimized.

Show comment
Hide comment
@domenkozar

domenkozar Aug 29, 2013

git checkout master curl https://github.com/project/repo/pulls/3.patch | git am

Done.

domenkozar commented Aug 29, 2013

git checkout master curl https://github.com/project/repo/pulls/3.patch | git am

Done.

@chadwhitacre

This comment has been minimized.

Show comment
Hide comment
@chadwhitacre

chadwhitacre Sep 3, 2013

@gnarf has some nice aliases at https://gist.github.com/gnarf/5406589.

$ git pr 537
From github.com:foo/bar
 * [new ref]         refs/pull/537/head -> pr/537
Switched to branch 'pr/537'
$ co master
Switched to branch 'master'
$ git pr-clean
Deleted branch pr/537 (was e17f10a).
$

chadwhitacre commented Sep 3, 2013

@gnarf has some nice aliases at https://gist.github.com/gnarf/5406589.

$ git pr 537
From github.com:foo/bar
 * [new ref]         refs/pull/537/head -> pr/537
Switched to branch 'pr/537'
$ co master
Switched to branch 'master'
$ git pr-clean
Deleted branch pr/537 (was e17f10a).
$
@rmcastil

This comment has been minimized.

Show comment
Hide comment
@rmcastil

rmcastil commented Sep 9, 2013

thanks @piscisaureus!

@ricbermo

This comment has been minimized.

Show comment
Hide comment
@ricbermo

ricbermo Nov 22, 2013

I prefer this method from @joelmccracken, Thanks, BTW.

git remote add other_user other_user_repo_url
git fetch other_user
git checkout -b other_user_branch other_user/branch

ricbermo commented Nov 22, 2013

I prefer this method from @joelmccracken, Thanks, BTW.

git remote add other_user other_user_repo_url
git fetch other_user
git checkout -b other_user_branch other_user/branch

@tzz

This comment has been minimized.

Show comment
Hide comment
@tzz

tzz Jan 6, 2014

clever, thanks!

tzz commented Jan 6, 2014

clever, thanks!

@jamiebuilds

This comment has been minimized.

Show comment
Hide comment
@jamiebuilds

jamiebuilds Jan 12, 2014

How would one add commits to a pr? With this:

git checkout pr/74
git commit -m 'Fixed some stuff'
git push origin pr/74

It creates a new branch pr/74

jamiebuilds commented Jan 12, 2014

How would one add commits to a pr? With this:

git checkout pr/74
git commit -m 'Fixed some stuff'
git push origin pr/74

It creates a new branch pr/74

@blbradley

This comment has been minimized.

Show comment
Hide comment
@blbradley

blbradley Jan 30, 2014

It would be superb if you could pull only open pull requests like this.

blbradley commented Jan 30, 2014

It would be superb if you could pull only open pull requests like this.

@pents90

This comment has been minimized.

Show comment
Hide comment
@pents90

pents90 Feb 7, 2014

@whit537, I' m getting the same issue as you (Your configuration specifies to merge with the ref 'pull/782'
from the remote, but no such ref was fetched), any idea how to fix?

pents90 commented Feb 7, 2014

@whit537, I' m getting the same issue as you (Your configuration specifies to merge with the ref 'pull/782'
from the remote, but no such ref was fetched), any idea how to fix?

@alexvbush

This comment has been minimized.

Show comment
Hide comment
@alexvbush

alexvbush Feb 7, 2014

Somehow I get this:

git fetch origin
fatal: refs/remotes/origin/pr/40 tracks both refs/heads/pr/40 and refs/pull/40/head
Unexpected end of command stream

Any ideas what it might be?

alexvbush commented Feb 7, 2014

Somehow I get this:

git fetch origin
fatal: refs/remotes/origin/pr/40 tracks both refs/heads/pr/40 and refs/pull/40/head
Unexpected end of command stream

Any ideas what it might be?

@beporter

This comment has been minimized.

Show comment
Hide comment
@beporter

beporter Feb 13, 2014

Is it possible for a maintainer to rebase a pull from a fork (instead of having to tell the originator of the PR to do it in their fork themselves?)

beporter commented Feb 13, 2014

Is it possible for a maintainer to rebase a pull from a fork (instead of having to tell the originator of the PR to do it in their fork themselves?)

@richhollis

This comment has been minimized.

Show comment
Hide comment
@richhollis

richhollis Feb 14, 2014

@JayMarshal - had the same problem and error message. I'd somehow managed to create a branch called pr/22. I verified this by seeing the branch in GitHub.

I used the following to delete the erroneous pr branch (from http://stackoverflow.com/questions/2003505/how-do-i-delete-a-git-branch-both-locally-and-remotely):

git push origin --delete pr/22

Everything now working correctly and I can pull again.

richhollis commented Feb 14, 2014

@JayMarshal - had the same problem and error message. I'd somehow managed to create a branch called pr/22. I verified this by seeing the branch in GitHub.

I used the following to delete the erroneous pr branch (from http://stackoverflow.com/questions/2003505/how-do-i-delete-a-git-branch-both-locally-and-remotely):

git push origin --delete pr/22

Everything now working correctly and I can pull again.

@MattiSG

This comment has been minimized.

Show comment
Hide comment
@MattiSG

MattiSG Feb 17, 2014

This gist breaks installing Homebrew

Sorry for shouting, lots of comments in here. Don't get me wrong: this won't break installing with brew, but this will break installing brew itself. Indeed, using this trick will give you brew issue #19436, and will probably break some other scripts.

Basically, if a repo does not yet have an origin set, the instruction from this gist will pretend it has. However, since it has no URL (which of course it couldn't, since we want it to be generic), no fetch can happen, but you also can't associate any new origin, since it already exists.

MattiSG commented Feb 17, 2014

This gist breaks installing Homebrew

Sorry for shouting, lots of comments in here. Don't get me wrong: this won't break installing with brew, but this will break installing brew itself. Indeed, using this trick will give you brew issue #19436, and will probably break some other scripts.

Basically, if a repo does not yet have an origin set, the instruction from this gist will pretend it has. However, since it has no URL (which of course it couldn't, since we want it to be generic), no fetch can happen, but you also can't associate any new origin, since it already exists.

@dolmen

This comment has been minimized.

Show comment
Hide comment
@dolmen

dolmen Mar 28, 2014

@beporter Yes, you can.
Just create a branch from the submitted branch: git checkout -b pr42-rebased pr/42 ; git rebase master.
As an alternative you can also just cherry-pick each commit of the pr.

dolmen commented Mar 28, 2014

@beporter Yes, you can.
Just create a branch from the submitted branch: git checkout -b pr42-rebased pr/42 ; git rebase master.
As an alternative you can also just cherry-pick each commit of the pr.

@iapilgrim

This comment has been minimized.

Show comment
Hide comment
@iapilgrim

iapilgrim commented May 5, 2014

It works

@haiy

This comment has been minimized.

Show comment
Hide comment
@haiy

haiy Jun 14, 2014

Sooo looooog....Greate.

haiy commented Jun 14, 2014

Sooo looooog....Greate.

@beedaan

This comment has been minimized.

Show comment
Hide comment
@beedaan

beedaan Jun 24, 2014

Thank You!

beedaan commented Jun 24, 2014

Thank You!

@dakcarto

This comment has been minimized.

Show comment
Hide comment
@dakcarto

dakcarto Sep 2, 2014

@piscisaureus It appears @jasoncodes's note about the order of the fetch lines is correct, i.e.:

[remote "origin"]
    url = git@github.com:joyent/node.git
    fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
    fetch = +refs/heads/*:refs/remotes/origin/*

If the PR fetch comes after the regular fetch, I end up with an ambiguous (and non-existent) remote tracking branch in SourceTree.app on Mac. After the reordering, as above, assigned remote tracking branch is accurate and pulling in new changes works (though I'm sure if the remote PR is rebased and force-pushed a new local branch will still need checked out, as per norm).

This may be specific to the way SourceTree auto-assigns a tracking branch, but nonetheless, works for me.

dakcarto commented Sep 2, 2014

@piscisaureus It appears @jasoncodes's note about the order of the fetch lines is correct, i.e.:

[remote "origin"]
    url = git@github.com:joyent/node.git
    fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
    fetch = +refs/heads/*:refs/remotes/origin/*

If the PR fetch comes after the regular fetch, I end up with an ambiguous (and non-existent) remote tracking branch in SourceTree.app on Mac. After the reordering, as above, assigned remote tracking branch is accurate and pulling in new changes works (though I'm sure if the remote PR is rebased and force-pushed a new local branch will still need checked out, as per norm).

This may be specific to the way SourceTree auto-assigns a tracking branch, but nonetheless, works for me.

@matthiasbeyer

This comment has been minimized.

Show comment
Hide comment
@matthiasbeyer

matthiasbeyer Sep 7, 2014

And also for the record, a fast-forward merge doesn't seem to close the PR in GitHub. That is, I rebased master onto pr/785, then merged pr/785 to master, then pushed, and the PR is still open.

This is a feature github is still missing: Recognizing fast-forward merges.

matthiasbeyer commented Sep 7, 2014

And also for the record, a fast-forward merge doesn't seem to close the PR in GitHub. That is, I rebased master onto pr/785, then merged pr/785 to master, then pushed, and the PR is still open.

This is a feature github is still missing: Recognizing fast-forward merges.

@frhd

This comment has been minimized.

Show comment
Hide comment
@frhd

frhd Nov 13, 2014

I love this shit.

frhd commented Nov 13, 2014

I love this shit.

@quickfur

This comment has been minimized.

Show comment
Hide comment
@quickfur

quickfur Nov 28, 2014

Wow. Thanks for posting this!! Just what I needed to rescue a pull request whose original submitter had deleted the repository of, so there was no other reference to the commits.

quickfur commented Nov 28, 2014

Wow. Thanks for posting this!! Just what I needed to rescue a pull request whose original submitter had deleted the repository of, so there was no other reference to the commits.

@harschware

This comment has been minimized.

Show comment
Hide comment
@twiecki

This comment has been minimized.

Show comment
Hide comment
@twiecki

twiecki Jan 1, 2015

This used to work fine but now I'm getting:

>>git pull origin
fatal: Cannot fetch both refs/pull/416/head and refs/heads/pr/416 to refs/remotes/origin/pr/416

Any idea?

EDIT: Turns out there was a remote branch named pr/416 I had to delete.

twiecki commented Jan 1, 2015

This used to work fine but now I'm getting:

>>git pull origin
fatal: Cannot fetch both refs/pull/416/head and refs/heads/pr/416 to refs/remotes/origin/pr/416

Any idea?

EDIT: Turns out there was a remote branch named pr/416 I had to delete.

@chernjie

This comment has been minimized.

Show comment
Hide comment
@chernjie

chernjie Feb 9, 2015

I did this so often that I wrote a tool to do it for me, hope you like it!
https://gist.github.com/chernjie/b16fe4dccf3f386d52ff

chernjie commented Feb 9, 2015

I did this so often that I wrote a tool to do it for me, hope you like it!
https://gist.github.com/chernjie/b16fe4dccf3f386d52ff

@njt1982

This comment has been minimized.

Show comment
Hide comment
@njt1982

njt1982 Feb 9, 2015

Once I am on one of these PR branches, is there anyway to find out the name of the branch this PR was made from?

Eg, say I had a PR open for master..my_feature and I checkout out pr/123... Is there any git command to tell me that ref points to the HEAD of my_feature?

njt1982 commented Feb 9, 2015

Once I am on one of these PR branches, is there anyway to find out the name of the branch this PR was made from?

Eg, say I had a PR open for master..my_feature and I checkout out pr/123... Is there any git command to tell me that ref points to the HEAD of my_feature?

@colinpade

This comment has been minimized.

Show comment
Hide comment
@colinpade

colinpade Mar 30, 2015

worked for me! Thanks for your efforts.

colinpade commented Mar 30, 2015

worked for me! Thanks for your efforts.

@livash

This comment has been minimized.

Show comment
Hide comment
@livash

livash May 1, 2015

Thanks for this post. Super helpful.

livash commented May 1, 2015

Thanks for this post. Super helpful.

@howtomakeaturn

This comment has been minimized.

Show comment
Hide comment
@howtomakeaturn

howtomakeaturn May 28, 2015

You know what? You are both cool and awesome.
Thanks a lot.

howtomakeaturn commented May 28, 2015

You know what? You are both cool and awesome.
Thanks a lot.

@mhotan

This comment has been minimized.

Show comment
Hide comment
@mhotan

mhotan commented Jun 10, 2015

👍

@facekapow

This comment has been minimized.

Show comment
Hide comment
@facekapow

facekapow Jul 26, 2015

100 X 👍, Thanks!

facekapow commented Jul 26, 2015

100 X 👍, Thanks!

@zldrq

This comment has been minimized.

Show comment
Hide comment
@zldrq

zldrq Aug 1, 2015

never saw that coming!

zldrq commented Aug 1, 2015

never saw that coming!

@ava-dylang

This comment has been minimized.

Show comment
Hide comment
@ava-dylang

ava-dylang Sep 3, 2015

In addition to

    fetch = +refs/pull/*/head:refs/remotes/origin/pr/*/head

I recommend grabbing the merge ref as well:

    fetch = +refs/pull/*/merge:refs/remotes/origin/pr/*/merge

Merge refs are the merge result from your branch to your merge target, they contain an exact copy of what the tip of the master will become when merged (well exact spare for an author perhaps)

ava-dylang commented Sep 3, 2015

In addition to

    fetch = +refs/pull/*/head:refs/remotes/origin/pr/*/head

I recommend grabbing the merge ref as well:

    fetch = +refs/pull/*/merge:refs/remotes/origin/pr/*/merge

Merge refs are the merge result from your branch to your merge target, they contain an exact copy of what the tip of the master will become when merged (well exact spare for an author perhaps)

@rr-

This comment has been minimized.

Show comment
Hide comment
@rr-

rr- Sep 4, 2015

Can I use this to recover active pull requests from deleted forks?

rr- commented Sep 4, 2015

Can I use this to recover active pull requests from deleted forks?

@gibffe

This comment has been minimized.

Show comment
Hide comment
@gibffe

gibffe Nov 3, 2015

nice one !

gibffe commented Nov 3, 2015

nice one !

@dorian-marchal

This comment has been minimized.

Show comment
Hide comment
@dorian-marchal

dorian-marchal Nov 16, 2015

Nice, thank you ❤️

dorian-marchal commented Nov 16, 2015

Nice, thank you ❤️

@ahmadawais

This comment has been minimized.

Show comment
Hide comment
@ahmadawais

ahmadawais Nov 19, 2015

I use a bash function for this

#
# Git Checkout a Pull Request locally.
#
# Usage: gfpr 8
# Where 8 is the number of pull request (can be found right after the PR's title).
# @author Ahmad Awais github.com/ahmadawais
#
function gfpr(){
  echo "${whitef}———————————————————${reset}"
    echo "${whiteb} ${blackf}0. Fetching the pull request...${reset}"

    git fetch origin pull/"${1}"/head:pull_"${1}"

    echo "${whiteb} ${blackf}1. PR fetched creating a branch...${reset}"

    git checkout pull_"${1}"

    echo "${whiteb} ${blackf}2. Checking out to a new PR branch...${reset}"

    echo "${greenb} ${blackf}3. PR Branch Created!!!${reset}"
  echo "${whitef}———————————————————${reset}"
}

ahmadawais commented Nov 19, 2015

I use a bash function for this

#
# Git Checkout a Pull Request locally.
#
# Usage: gfpr 8
# Where 8 is the number of pull request (can be found right after the PR's title).
# @author Ahmad Awais github.com/ahmadawais
#
function gfpr(){
  echo "${whitef}———————————————————${reset}"
    echo "${whiteb} ${blackf}0. Fetching the pull request...${reset}"

    git fetch origin pull/"${1}"/head:pull_"${1}"

    echo "${whiteb} ${blackf}1. PR fetched creating a branch...${reset}"

    git checkout pull_"${1}"

    echo "${whiteb} ${blackf}2. Checking out to a new PR branch...${reset}"

    echo "${greenb} ${blackf}3. PR Branch Created!!!${reset}"
  echo "${whitef}———————————————————${reset}"
}

@IngwiePhoenix

This comment has been minimized.

Show comment
Hide comment
@IngwiePhoenix

IngwiePhoenix Dec 31, 2015

There needs to be something in upstream git that just...does that. or at least in github/hub :p

IngwiePhoenix commented Dec 31, 2015

There needs to be something in upstream git that just...does that. or at least in github/hub :p

@sideshowbarker

This comment has been minimized.

Show comment
Hide comment
@sideshowbarker

sideshowbarker Jan 25, 2016

@tomjenkinson & @jimi-c: About removing any remote pull ref from a github repo, I’m pretty sure you can’t. If you could, the way would be:

git push --delete origin refs/pull/1/head

…where 1 is of course the PR number for whatever pull ref you want to remove.

But if you try that, you’ll get a message saying something like:

! [remote rejected] refs/pull/1/head (deny updating a hidden ref)

…the reason being that the github remote refs/pull/ namespace is a (synthetic) read-only namespace.

sideshowbarker commented Jan 25, 2016

@tomjenkinson & @jimi-c: About removing any remote pull ref from a github repo, I’m pretty sure you can’t. If you could, the way would be:

git push --delete origin refs/pull/1/head

…where 1 is of course the PR number for whatever pull ref you want to remove.

But if you try that, you’ll get a message saying something like:

! [remote rejected] refs/pull/1/head (deny updating a hidden ref)

…the reason being that the github remote refs/pull/ namespace is a (synthetic) read-only namespace.

@bf4

This comment has been minimized.

Show comment
Hide comment
@bf4

bf4 Jan 28, 2016

A stupid way to recover a commit that has been rebased and is now unreachable:

  1. Given unreachable commit https://github.com/org/repo/commits/332a2b9f43f1f8d7730e0a01356ea183dfadd470
  2. See if you can compare them to any earlier commit you have https://github.com/org/repo/compare/f571415f4da9cc28edc83242e353966677dabcd2...332a2b9f43f1f8d7730e0a01356ea183dfadd470
  3. Push your local commit up to a recovery branch git checkout f571415f4da9cc28edc83242e353966677dabcd2; git checkout -b recovery; git push origin recovery
  4. See the patch commits https://github.com/org/repo/compare/recovery...332a2b9f43f1f8d7730e0a01356ea183dfadd470.patch and download as recovery.patch (you could curl unless it's private so blah blah)
  5. Apply the patch commits and push up. git am recovery.patch && git push origin recovery

bf4 commented Jan 28, 2016

A stupid way to recover a commit that has been rebased and is now unreachable:

  1. Given unreachable commit https://github.com/org/repo/commits/332a2b9f43f1f8d7730e0a01356ea183dfadd470
  2. See if you can compare them to any earlier commit you have https://github.com/org/repo/compare/f571415f4da9cc28edc83242e353966677dabcd2...332a2b9f43f1f8d7730e0a01356ea183dfadd470
  3. Push your local commit up to a recovery branch git checkout f571415f4da9cc28edc83242e353966677dabcd2; git checkout -b recovery; git push origin recovery
  4. See the patch commits https://github.com/org/repo/compare/recovery...332a2b9f43f1f8d7730e0a01356ea183dfadd470.patch and download as recovery.patch (you could curl unless it's private so blah blah)
  5. Apply the patch commits and push up. git am recovery.patch && git push origin recovery
@emilio2hd

This comment has been minimized.

Show comment
Hide comment
@emilio2hd

emilio2hd commented Mar 6, 2016

Thank you

@denysdovhan

This comment has been minimized.

Show comment
Hide comment
@denysdovhan

denysdovhan Mar 13, 2016

Is there way to get only opened pull requests, not all? Because I don't wanna see already merged requests.

denysdovhan commented Mar 13, 2016

Is there way to get only opened pull requests, not all? Because I don't wanna see already merged requests.

@brucechou1983

This comment has been minimized.

Show comment
Hide comment
@brucechou1983

brucechou1983 Mar 22, 2016

Thank you. It's helpful!

brucechou1983 commented Mar 22, 2016

Thank you. It's helpful!

@alisniffer

This comment has been minimized.

Show comment
Hide comment
@alisniffer

alisniffer Mar 22, 2016

Thank you. It's helpful!

alisniffer commented Mar 22, 2016

Thank you. It's helpful!

@hayd

This comment has been minimized.

Show comment
Hide comment
@hayd

hayd Apr 27, 2016

@sideshowbarker (@tomjenkinson @jimi-c)

whilst pull is readonly, it seems you can remove from the heads.

git push --delete upstream refs/heads/pr/521

This seems to fix the issue for our team (the PR/branch has since been deleted... I'm hoping it won't come back).

hayd commented Apr 27, 2016

@sideshowbarker (@tomjenkinson @jimi-c)

whilst pull is readonly, it seems you can remove from the heads.

git push --delete upstream refs/heads/pr/521

This seems to fix the issue for our team (the PR/branch has since been deleted... I'm hoping it won't come back).

@amirj700

This comment has been minimized.

Show comment
Hide comment
@amirj700

amirj700 May 18, 2016

Very Useful thanks.

amirj700 commented May 18, 2016

Very Useful thanks.

@cvvs

This comment has been minimized.

Show comment
Hide comment
@cvvs

cvvs commented Aug 12, 2016

👍

@njql007

This comment has been minimized.

Show comment
Hide comment
@njql007

njql007 Sep 1, 2016

This is useful, thank you!

njql007 commented Sep 1, 2016

This is useful, thank you!

@drupol

This comment has been minimized.

Show comment
Hide comment
@drupol

drupol Sep 13, 2016

Hi,

Thanks for the useful tip !
One drawback only, how to update it's local branch when someone added a commit to the pull request ?
I tried git pull in the local branch, but I got this error:

pol@localhost ~/d/g/mysite> git pull
Your configuration specifies to merge with the ref 'pr/4'
from the remote, but no such ref was fetched.
pol@localhost ~/d/g/mysite>

drupol commented Sep 13, 2016

Hi,

Thanks for the useful tip !
One drawback only, how to update it's local branch when someone added a commit to the pull request ?
I tried git pull in the local branch, but I got this error:

pol@localhost ~/d/g/mysite> git pull
Your configuration specifies to merge with the ref 'pr/4'
from the remote, but no such ref was fetched.
pol@localhost ~/d/g/mysite>
@ohdoking

This comment has been minimized.

Show comment
Hide comment
@ohdoking

ohdoking Sep 28, 2016

oh so nice tip

ohdoking commented Sep 28, 2016

oh so nice tip

@clemens-tolboom

This comment has been minimized.

Show comment
Hide comment
@clemens-tolboom

clemens-tolboom Oct 6, 2016

Reading https://git-scm.com/book/en/v2/Git-Internals-The-Refspec I do not see a command to add this ***** refspecs

It seems one can fetch an individual PR by something like git fetch origin master:refs/remotes/origin/mymaster but I haven't figured out as adding the whole lot is much simpler as most of the time one is interested in more then one PR

clemens-tolboom commented Oct 6, 2016

Reading https://git-scm.com/book/en/v2/Git-Internals-The-Refspec I do not see a command to add this ***** refspecs

It seems one can fetch an individual PR by something like git fetch origin master:refs/remotes/origin/mymaster but I haven't figured out as adding the whole lot is much simpler as most of the time one is interested in more then one PR

@jkryanchou

This comment has been minimized.

Show comment
Hide comment
@jkryanchou

jkryanchou Oct 9, 2016

awesome job it could either checkout upstream pull requests.

jkryanchou commented Oct 9, 2016

awesome job it could either checkout upstream pull requests.

@anhhh11

This comment has been minimized.

Show comment
Hide comment
@anhhh11

anhhh11 Oct 11, 2016

awesome \o/

anhhh11 commented Oct 11, 2016

awesome \o/

@membphis

This comment has been minimized.

Show comment
Hide comment
@membphis

membphis Nov 17, 2016

great job. thanks a lots

membphis commented Nov 17, 2016

great job. thanks a lots

@mosheeshel

This comment has been minimized.

Show comment
Hide comment
@mosheeshel

mosheeshel Nov 22, 2016

Is there any way to make the local branch track the remote branch the PT is based on?

mosheeshel commented Nov 22, 2016

Is there any way to make the local branch track the remote branch the PT is based on?

@tucq88

This comment has been minimized.

Show comment
Hide comment
@tucq88

tucq88 Nov 25, 2016

First, thanks for this great gist. But second, I want to ask if anyone figure out a way to list only current opening PRs ? Listing all of them (include with closed PRs) is not very ...productive
@denysdovhan Did you find a way to do so ?

tucq88 commented Nov 25, 2016

First, thanks for this great gist. But second, I want to ask if anyone figure out a way to list only current opening PRs ? Listing all of them (include with closed PRs) is not very ...productive
@denysdovhan Did you find a way to do so ?

@Buzz-Lightyear

This comment has been minimized.

Show comment
Hide comment
@Buzz-Lightyear

Buzz-Lightyear Mar 3, 2017

Neat, thanks!

Buzz-Lightyear commented Mar 3, 2017

Neat, thanks!

@kwhitley

This comment has been minimized.

Show comment
Hide comment
@kwhitley

kwhitley Mar 9, 2017

👍 Very useful!

kwhitley commented Mar 9, 2017

👍 Very useful!

@sajhak

This comment has been minimized.

Show comment
Hide comment
@sajhak

sajhak Mar 22, 2017

nice and useful (y)

sajhak commented Mar 22, 2017

nice and useful (y)

@tristanlee85

This comment has been minimized.

Show comment
Hide comment
@tristanlee85

tristanlee85 Apr 4, 2017

This has been very helpful. Thank you!

It looks like it was asked previously, but just in case I missed the reply, is there a way to list only the ones that are open? My dropdown in SourceTree now shows about 21k PRs while only ~70 are actually open.

tristanlee85 commented Apr 4, 2017

This has been very helpful. Thank you!

It looks like it was asked previously, but just in case I missed the reply, is there a way to list only the ones that are open? My dropdown in SourceTree now shows about 21k PRs while only ~70 are actually open.

@thomasaarholt

This comment has been minimized.

Show comment
Hide comment
@thomasaarholt

thomasaarholt May 22, 2017

I am still missing a way to do a git pull after checking out a PR. When I call git pull I get the following message. git fetch works fine.

Your configuration specifies to merge with the ref 'refs/heads/pr/1544'
from the remote, but no such ref was fetched.

The solution for now is to delete the branch, and then check it out again:

git branch -D pr/1544
git checkout pr/1544

Does anyone have any advice?

thomasaarholt commented May 22, 2017

I am still missing a way to do a git pull after checking out a PR. When I call git pull I get the following message. git fetch works fine.

Your configuration specifies to merge with the ref 'refs/heads/pr/1544'
from the remote, but no such ref was fetched.

The solution for now is to delete the branch, and then check it out again:

git branch -D pr/1544
git checkout pr/1544

Does anyone have any advice?

@bagong

This comment has been minimized.

Show comment
Hide comment
@bagong

bagong Jul 9, 2017

@thomasaarholt, I agree, the weakness of this otherwise lovely approach is that it seems not to be possible to track the pull request and resynchronize easily with subsequent commits. By now Github itself promotes checking out the PR from the remote branch the PR is based upon. This has multiple advantages:

  • the PR has a meaningful name, not just a number
  • if you have commit rights to the repo the PR is targeted at and the user did not disable editing of his/her pr, you can directly push to the PR and thereby speed up the review process
  • and of course you get a proper tracking branch

Getting used to working with remotes makes life with Git so much more worthwhile ;)

bagong commented Jul 9, 2017

@thomasaarholt, I agree, the weakness of this otherwise lovely approach is that it seems not to be possible to track the pull request and resynchronize easily with subsequent commits. By now Github itself promotes checking out the PR from the remote branch the PR is based upon. This has multiple advantages:

  • the PR has a meaningful name, not just a number
  • if you have commit rights to the repo the PR is targeted at and the user did not disable editing of his/her pr, you can directly push to the PR and thereby speed up the review process
  • and of course you get a proper tracking branch

Getting used to working with remotes makes life with Git so much more worthwhile ;)

@dougludlow

This comment has been minimized.

Show comment
Hide comment
@dougludlow

dougludlow Aug 16, 2017

If you want to update a pr/1234 branch locally (resynchronize), you can git pull origin refs/pull/1234/head.

dougludlow commented Aug 16, 2017

If you want to update a pr/1234 branch locally (resynchronize), you can git pull origin refs/pull/1234/head.

@sduensin

This comment has been minimized.

Show comment
Hide comment
@sduensin

sduensin Oct 17, 2017

Just another "Thank you"! Very handy!

sduensin commented Oct 17, 2017

Just another "Thank you"! Very handy!

@xuexb

This comment has been minimized.

Show comment
Hide comment
@xuexb

xuexb Oct 26, 2017

Thank you~

xuexb commented Oct 26, 2017

Thank you~

@gondre

This comment has been minimized.

Show comment
Hide comment
@gondre

gondre commented Nov 7, 2017

Thanks!

@mobajm

This comment has been minimized.

Show comment
Hide comment
@mobajm

mobajm Nov 11, 2017

Thank you for this. For a reason I don't know I couldn't retrieve only the PR of interest to me, but this approach worked nicely.

mobajm commented Nov 11, 2017

Thank you for this. For a reason I don't know I couldn't retrieve only the PR of interest to me, but this approach worked nicely.

@agilewarealok

This comment has been minimized.

Show comment
Hide comment
@agilewarealok

agilewarealok Dec 5, 2017

Thanks for this buddy!

agilewarealok commented Dec 5, 2017

Thanks for this buddy!

@kistters

This comment has been minimized.

Show comment
Hide comment
@kistters

kistters commented Feb 22, 2018

THX

@nishantrayan

This comment has been minimized.

Show comment
Hide comment
@nishantrayan