Skip to content

Instantly share code, notes, and snippets.

@kerrizor
Forked from gvaughn/copr.md
Created April 17, 2016 20:07
Show Gist options
  • Save kerrizor/d2c6783fabb9244bdb78c8d60e9b0419 to your computer and use it in GitHub Desktop.
Save kerrizor/d2c6783fabb9244bdb78c8d60e9b0419 to your computer and use it in GitHub Desktop.
git copr alias

I'd like to share some git aliases that you might find useful if you handle pull requests from others.

Add these to your ~/.gitconfig in the [alias] section:

copr = "!f() { git fetch -fu origin refs/pull/$1/head:pr-$1; git checkout pr-$1; } ; f"
prunepr = "!git for-each-ref refs/heads/pr-* --format='%(refname:short)' | while read ref ; do git branch -D $ref ; done"

Now you can "git copr #{pr_number}" (check out pull request is the mnemonic) and it will pull down the PR in a local branch of pr-#{pr_number} and check it out for you. To do it right, you must pronounce it "Copper" with a James Cagney gangster accent.

And if you use this regularly, you're going to end up with a bunch of pr-* local branches, so "git prunepr" will get rid of them for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment