Norway


I love the traditional GitHub workflow of receive pull request, pull down pull request to test, and merge the pull request.  GitHub makes the first and the third steps easy but pulling down pull requests from new contributors requires some boilerplate work that annoys me…

…namely navigating to their fork and copying the fork address so that I can do:

 pull https://github.com/some-new-user/repo. branch-name

And since you don’t know if the author will be contributing more in the future, there’s no point in adding them as a remote (via git remote add) R; you’ll just muddy up your remote listing.

After years of this annoying dance I’ve found TeamPorcupine’s awesome git alias for easily pulling down pull requests:

git config --global --add alias. '!f() { git fetch -fu ${2:-upstream} refs/pull/$1/head:/$1 && git checkout /$1; }; f'

git config --global --add alias.-clean '!git checkout master ; git for-each-ref refs/heads//* --format="%(refname)" | while read ref ; do branch=${ref#refs/heads/} ; git branch -D $branch ; done'

The first alias above, git pr, allows you to pull down a pull request by ID, creating an new branch for it:

~/Projects/debugger.html (master) $ git pr 4862
From https://github.com/devtools-html/debugger.html
 * [new ref]           refs/pull/4862/head -> pr/4862
Switched to branch 'pr/4862'

~/Projects/debugger.html (pr/4862) $

The second alias, git pr-clean, deletes all branches created with git pr:

~/Projects/debugger.html (pr/4862) $ git pr-clean
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 190 commits.
  (use "git push" to publish your local commits)
husky > npm run -s postcheckout (node v8.5.0)

Deleted branch pr/4862 (was 10fe5049).
~/Projects/debugger.html (master) $

Note: You must have a remote called upstream which points to the upstream repo.

I can’t tell you how happy I am to have this pr git alias, and how much of a bonus the pr-clean alias is.  Checking out PRs will be so much and I can focus more on code and functional review than process!

The post Faster PR Pulls with Git Aliases appeared first on David Walsh Blog.

faster pr pulls with git aliases - ba vlny16 pc20dwalsh 20160705 - Faster PR Pulls with Git Aliases



Source link

LEAVE A REPLY

Please enter your comment!
Please enter your name here