Skip to content

Instantly share code, notes, and snippets.

@vinitatandulkar
Forked from weppos/git-prs.md
Created January 17, 2019 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vinitatandulkar/785da2de47137ffde4a7509c6d89624e to your computer and use it in GitHub Desktop.
Save vinitatandulkar/785da2de47137ffde4a7509c6d89624e 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