I never mind reviewing PRs from my coworkers, but I do want to minimize interruptions knowing I typically have other tasks in-flight. To help make the overhead of switching contexts (and branches) more efficient, try using the git pr command found in https://github.com/tj/git-extras!
Also, note that throughout this post I reference the
git pr command because I mostly use GitHub. However, you can also use the related
git mr command with GitLab! So keep that in mind throughout the rest of this post.
First, you’ll need to install git-extras. For most Mac users, this is all you need:
$ brew install git-extras
Note: Installing from Homebrew will not give you the option omit certain git-extras if they conflict with existing git aliases. To have this option, build from source.
Show me how!
Let’s say you’re chugging along on your own feature branch and you’ve reached a stopping point where you can safely switch contexts and help keep your team’s PRs from piling up …
- Commit or stash your changes. You don’t want to lose any work, and trying to checkout another branch will result in an error, so finish up what you’re doing and commit/stash first. Also, you might consider that if you’re not ready to commit the code changes you’ve made, you might not be cognitively ready to switch contexts anyway 🤓
- Pull the PR down for review. Just run $ git pr 123 from within your existing working directory, replacing 123 with the appropriate PR number, or even the full URL to the PR.If you’re working from a fork, you can also specify a different remote, e.g., $ git pr 123 upstream . (See the git pr docs for more information.) Doing so will automatically checkout the 123 branch as pr/123 .Bonus! If no new packages have been added/updated in package.json, you might not even need to restart your web server when checking out other branches. (Lingua changes may still require a restart, however.)
- Do your review thang. Bring the site up, test it thoroughly, leave good feedback on GitHub … (you know the drill)
- Switch back to your branch. You’ll need to switch back to your own feature branch before cleaning up the PR branch you pulled down.
- Clean it up. Run $ git pr clean to delete the PR branch and continue with your own feature work.
You should now be back in your own lane after helping to get your team’s commits reviewed and merged, having a strong sense of pride and accomplishment, and a minimum amount of time spent.