Github Aliases for working with a team

These are a few helpful aliases for checking out the head of a github pull request and adding git remotes for other users forks.


copr

Checkout a github pull request by pull request number. The PR is checked out in a 'detached HEAD' state so you will want to create a branch if you intend to contribute any changes.

copr = !sh -c 'git fetch upstream refs/pull/${1}/head && git checkout FETCH_HEAD' -  

Usage:

$ git copr 42

Quick add:

$ git config --global alias.copr \!sh\ -c\ \'git\ fetch\ upstream\ refs/pull/\$\{1\}/head\ \&\&\ git\ checkout\ FETCH_HEAD\'\ -

team-remote

Checkout a team member's fork of a github repo. Simply substituting the username component of the git url with the parameter provided.

team-remote = !sh -c 'git remote add $1 $(git config --get remote.origin.url | sed -E \"s|([^:]+:)([^/]+)(/.+)|\\1$1\\3|g\") && git fetch $1' -  

Usage:

$ git team-remote otherusername
$ git checkout otherusername/feature-branch

Quick add:

$ git config --global alias.team-remote \!sh\ -c\ \'git\ remote\ add\ \$1\ \$\(git\ config\ --get\ remote.origin.url\ \|\ sed\ -E\ \"s\|\(\[\^:\]+:\)\(\[\^/\]+\)\(/.+\)\|\\1\$1\\3\|g\"\)\ \&\&\ git\ fetch\ \$1\'\ -

The hub git wrapper is also helpful:

https://github.com/github/hub