Git is a very powerful revision control system used in software development, and at this point, is effectively the industry standard. One of the things that makes Git so powerful is that there are all sorts of low-level operations that developers can do in it. This includes everything from tagging releases, to having an insane number of branches, to painless merging of said branches, to rewriting history.
If you’re new to Git, your brain probably threw an exception when reaching the end of the paragraph as you thought to yourself, “Wait WHAT? Why would you want to REWRITE HISTORY?” Good question! Normally, you don’t want to mess history in a revision control system. But sometimes you may want to or even need to. A few possible reasons for rewriting history include:
- Feature Branch “B” is a branch of Feature Branch “A” and you want to merge B’s changes to master, but not A’s.
- Squashing all the commits in a feature branch to a single commit, after having previously pushed those commits.
- A developer made a commit with something that doesn’t belong in Git, such as PII or credentials.
- You want to “clean up” the commit history a little.
Whether any of the above are fully valid reasons or not is something up to you and your dev team.
That said, rebasing is not something you want to experiment with for the first time on your production repo. It’s just a bad idea. So I built a playground/lab where anyone can experiment with git rebasing in an isolated and local environment, which can be stood up in seconds. Here’s how to get started:
git clone git@github.com:dmuth/git-rebase-i-playground.git
cd git-rebase-i-playground
./init.sh
The above will create the following repo and directories, each with about a dozen commits:
dev-alice– A clone of the repo made by “Alice”, with two branches:branch1andbranch2.branch1is a branch from master whilebranch2is based onbranch1. That is by design (and is based on a True Story, heh).dev-bob– A clone of the repo made by Alice’s co-worker “Bob”, only containingmaster.repo.git– A “bare” clone of the repo. Note that if youcdto this directory, commands likegit log --pretty=onelinewill work just fine. That is useful for debugging.
The commit graph looks like this:
From there, you can play around in the repos as much as you like. To re-create everything so you can start again from Square One, just run init.sh again.
If you’re looking for some sample exercises, here’s a list:
- Switch the order of commits
04-fourthand05-fifth - Switch the order of commits
01-first-will-conflictand02-second-will-conflict - Merge the changes of
branch2intomasterbut NOT the changes ofbranch1 - Squash the two commits in
branch1then push toorigin - Switch the order of commits
04-fourth and 05-fifth, push toorigin - Switch the order of commits
01-first-will-conflictand02-second-will-conflict, THEN push toorigin - Run
git rebase -iand delete commit05-fifth. Then recover it.
If you’d like to view hints or solutions to all of the above exercises, they can be found on the page for the GitHub repo itself, at: https://github.com/dmuth/git-rebase-i-playground
Enjoy!

