Photo by Joice Kelly on Unsplash

Squash and Rebase — Git Basics

James Woodall
The Startup
Published in
5 min readFeb 15, 2021

--

Let’s say you’re working on a project with 2 other developers. You’re each being good citizens and checking in your code to feature branches. Then, when the time is right, those branches will be checked into the main branch. All good.

However, fast forward a few months and your git history will likely end up looking something like this! Yikes.

It’s almost impossible to decipher what went on and if you need to track down a bug … good luck.

If keeping a squeaky clean commit tree is something you’d like to do then enter Git Squash and Git Rebase.

Rebase

When completing a Pull Request the maintainer of the project by default will just simply “Merge” the pull request. This will take all of the commits from your feature branch, and push them to the HEAD of the destination branch (usually the main branch). Sometimes you’ll get a nice “Merge” commit saying what branch it came from, but if your branch contained 20 commits, the destination branch has grown by 20 commits.

On the face of it, this seems sensible.

--

--

James Woodall
The Startup

James has been working in software development for several years and loves programming for web and wearable devices.