My current favorite command line alias is mgrim, composed of four other aliases. Here’s what it is, and what it does.

alias gmr='gco master && gpr && gco - && git rebase master'
alias grim='git rebase -i master'
alias mgrim='gmr && grim'

Starting from a feature branch:

  • gmr - checkout the master branch (gco is a Hashrocket alias for git checkout. Pull from origin/master and try to put my commits in the right place in history (gpr is a Hashrocket alias for git pull --rebase). Checkout my feature branch. Fast-forward my branch to the top of master (as though I had branched off master’s current HEAD.
  • grim - Open an interactive rebase to cleanup everything on my branch (see ‘Squash Your PR’)

I use feature branches for work, and use this command right before merging into master. The result? I’m always forced to look at my branch history and squash it down to the minimum, which is good for everyone (including future me). And, I never have a merge conflict with master.