Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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