Idiot-proof Git Rebasing

đź‘‹ FYI, this note is over 6 months old. Some of the content may be out of date.
On this page

By adding these aliases to your git config, you will be able to simplify rebasing.

[alias]
# *********************
# Rebase workflow
mainbranch = "!git remote show origin | sed -n '/HEAD branch/s/.*: //p'"
sync = "!git pull origin $(git mainbranch) --rebase"
update = "!git pull origin $(git rev-parse --abbrev-ref HEAD) --rebase"
squash = "!git rebase -v -i $(git mainbranch)"
publish = push origin HEAD --force-with-lease
pub = publish

Sync your branch with main Jump to heading

The sync command will get your local branch up to date with your main branch (main or master) at origin (ie Github).

git sync

Publish your branch’s changes to the world Jump to heading

The publish (abbrev pub) command publishes your changes to your remote branch. If other changes have been posted by another user to the remote, then changes will be rejected. You should update first to incorporate their changes and resolve any conflicts.

git publish
git pub

Update your branch with Github’s copy of your branch Jump to heading

If your local branch gets out of date with origin’s version of your branch, then do an update. This would happen if you’re collaborating on the branch with a colleague and need to get up to date.

git update

Squash commits Jump to heading

Prior to merging, you likely want to shrink your branch’s many noisy commits to one or two meaningful ones. That’s what squash command does, giving you a chance to rewrite the branch’s history.

git squash

← Back home