Skip to content

Instantly share code, notes, and snippets.

@wisetara
Forked from gvaughn/copr.md
Created April 11, 2016 19:09
Show Gist options
  • Save wisetara/d123adcee8eca045de2ef8dd60eac90e to your computer and use it in GitHub Desktop.
Save wisetara/d123adcee8eca045de2ef8dd60eac90e 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