Skip to content

Git Rebase 👷🏼‍♂️👷🏼‍♀️

Squashing commits

git rebase -i HEAD~2

In the next file prefix the commits to be squashed with either 's' or 'f'

squash - means that you can rename the new commit fixup - will merge that commit into other commit without any renaming

Renaming a commit

git rebase -i HEAD~1

In the next file prefix commit with 'r', then exit.
A new file will be opened in which you can update the commit message.

Dropping a commit

git rebase -i HEAD~1

In the next file, prefix the commit with 'd'.

Git Push after Rebase

After a git rebase, push the branch back up to the remote server with

git push origin [branch_name] -f

-f is essential as rebase modifies your git history and needs to be forced.

Rebasing on master

You have multiple branches... rebase1

You merge one branch (blue), but now the other branch is out of sync with the master branch. rebase2

From the branch (green) you want to rebase:

git fetch

This downloads all the references the green branch will need, then rebase with

git rebase origin/master
git push origin [my_branch] -f

And we end up with...

rebase3