Today I Learned

Single command to rebase branch on updated master

Having branch protection enabled in github prevents merging PR’s if the branch is out of date with target branch. Imgur

In github UI is a button to update branch, but it creates additional merge commit. To not have additional merge commit rebase the branch yourself.

It requires a few steps:

  • checkout master
  • pull master branch
  • checkout to your branch
  • rebase your branch on the new master
  • push with force

Here is the command to make all that automatically

git checkout master & git pull & git checkout - && git rebase master && git push --force-with-lease

Adding alias makes it easier to remember.

alias grbm="git checkout master & git pull & git checkout - && git rebase master && git push --force-with-lease"