Skip to content

Instantly share code, notes, and snippets.

@tuliren
Forked from gnarf/..git-pr.md
Created July 19, 2016 19:11
Show Gist options
  • Save tuliren/82b2083dddf755255c6f44af81a658d8 to your computer and use it in GitHub Desktop.
Save tuliren/82b2083dddf755255c6f44af81a658d8 to your computer and use it in GitHub Desktop.
Global .gitconfig aliases for GitHub Pull Request Managment

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
[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"
#!/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