/

Git rebase interactive

One of the most - imho - usefull git commands I use, but sometimes forget how it works is git rebase with the interactive option. Hence this post.

git rebase -i

So, if you’ve multiple commits in a git branch which are not very explandatory - like WIP - and you want to smash that into one commit before opening up a pull request, the git rebase -i command can fix that.

Let’s say you’ve three commits (Foo, Bar, Spam) and want to smash those down into one commit.

This can be done with the following command:

git rebase -i HEAD~3

This opens up your default text editor and gives the option to pick or squash (s) the commits:

pick 7366e3a # Foo
squash 3ac7cae # Bar
s 6aecb79 # Spam

Next; write your commit message and push your changes.