Skip to content

Instantly share code, notes, and snippets.

@weppos
Created March 28, 2016 23:30
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save weppos/53d0fceba6de5cba23ff to your computer and use it in GitHub Desktop.
Save weppos/53d0fceba6de5cba23ff to your computer and use it in GitHub Desktop.
PRs as Git Branches

If you want to download GitHub PRs to your local repository, you can use a little trick to download them as local branches.

Open the repository configuration file (.git/config) and search for the origin block. Change it from:

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

to (notice the fourth line):

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

Now fetch origin again:

$ git fetch origin

and use git branch -a to see all the PRs:

$ git branch -a

* master
  ...
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/origin/pr/104
  remotes/origin/pr/105
  remotes/origin/pr/112
  remotes/origin/pr/118

You can checkout to a specific PR:

$ git checkout origin/pr/118

and create a branch from it.

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