Skip to content

Instantly share code, notes, and snippets.

@MichaelEvans
Forked from gvaughn/copr.md
Created January 13, 2020 00:03
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 MichaelEvans/043d7c8b155734630328886e2e043004 to your computer and use it in GitHub Desktop.
Save MichaelEvans/043d7c8b155734630328886e2e043004 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