Skip to content

Instantly share code, notes, and snippets.

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 =

to (notice the fourth line):

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url =
	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

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