ampad

Nachhaltige Software

Yes­ter­day I was search­ing for a way to check­out Git­Hub pull re­quests and re­view them loc­ally that is more con­veni­ent than adding new re­motes.

For­tu­nately Fil­ippo Valsorda doc­u­mented how you can fetch a pull re­quest via

git fetch origin refs/pull/PR_NUMBER/head:LOCAL_BRANCH

Be­cause I like ali­ases I cre­ated this little ali­as which goes in­to your ~/.git­con­fig

[aliases]
pr = !sh -c '(test -n \"$1\" -a -n \"$2\" && \
      git fetch origin refs/pull/$1/head:pr_$1_$2) || \
      echo \"usage: git pr pull_request_number branch_name\"' -

This al­lows you to do

git pr 37 usablitiy_improvements

which will check out the Git­Hub pull re­quest num­ber 37 in­to a loc­al branch pr_37_usabilitiy_improvements where you can do whatever you'd like to do with it.