Skip to content

Instantly share code, notes, and snippets.

@gvaughn
Last active January 30, 2024 16:11
Show Gist options
  • Save gvaughn/f3c7897a51e52138eac1 to your computer and use it in GitHub Desktop.
Save gvaughn/f3c7897a51e52138eac1 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