Skip to content

Instantly share code, notes, and snippets.

@natros
Forked from gnarf/..git-pr.md
Created January 21, 2017 10:55
Show Gist options
  • Save natros/11193a74bb07c3d4871dab23fdff184f to your computer and use it in GitHub Desktop.
Save natros/11193a74bb07c3d4871dab23fdff184f to your computer and use it in GitHub Desktop.
Global .gitconfig aliases for 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 remotes:

  • git pr 4 - creates local branch pr/4 from the github 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
  • git spr - Same as git pr command, but for bitbucket/stash remotes
# for github remotes
[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"
# for bitbucket/stash remotes
spr = "!f() { git fetch -fu ${2:-origin} refs/pull-requests/$1/from:pr/$1 && git checkout pr/$1; }; f"
#!/bin/sh
# For github
git config --global alias.pr '!f() { git fetch -fu ${2:-origin} refs/pull/$1/head:pr/$1 && git checkout pr/$1; }; f'
git config --global 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'
# For stash/bitbucket
git config --global alias.spr '!f() { git fetch -fu ${2:-origin} refs/pull-requests/$1/from:pr/$1 && git checkout pr/$1; }; f'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment