Skip to content

Instantly share code, notes, and snippets.

@Spaceghost
Forked from gnarf/..git-pr.md
Last active August 29, 2015 14:11
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 Spaceghost/5bbdd14cfc1a87bb9872 to your computer and use it in GitHub Desktop.
Save Spaceghost/5bbdd14cfc1a87bb9872 to your computer and use it in GitHub Desktop.
[alias]
pr = "!f() { git fetch -fu ${2:-origin} refs/pull/$1/head:pr/$1 && git checkout pr/$1; }; f"
pr-clean = "!git for-each-ref refs/heads/pr/* --format='%(refname)' | while read ref ; do branch=${ref#refs/heads/} ; git branch -D $branch ; done"

Install

Either copy the aliases from the .gitconfig or run the commands in add-pr-alias.sh

Usage

Easily checkout local copies of pull requests from GitHub remotes:

  • git pr 4 - creates local branch pr/4 from the origin remote and checks it out
  • git pr 4 upstream - creates local branch pr/4 from upstream remote and checks it out
  • git pr-clean - removes all pr/* branches from your local repo
#!/bin/sh
git config --global --add alias.pr '!f() { git fetch -fu ${2:-origin} refs/pull/$1/head:pr/$1 && git checkout pr/$1; }; f'
git config --global --add alias.pr-clean '!git for-each-ref refs/heads/pr/* --format="%(refname)" | while read ref ; do branch=${ref#refs/heads/} ; git branch -D $branch ; done'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment