loading...
Cover image for Pick. Squash. Drop. Rebase! (Comic)

Pick. Squash. Drop. Rebase! (Comic)

erikaheidi profile image Erika Heidi Updated on ・2 min read

Git Rebase allows us to rewrite Git history. It is a common practice to use git rebase to squash commits before creating or merging a pull request; nobody needs to see that you fixed 10 typos in 5 separate commits, and keeping that history is of no use. So how does a rebase look like?

Git Rebase Comic

Let's imagine you have your deck of cards, they are ordered in a certain way that cannot be changed. Each card represents a commit in a project's branch.

When running an interactive rebase with rebase -i, there are mainly three actions we may want to perform in a commit (card):

  • pick: pick a commit.
  • squash: squash this commit into the previous one.
  • drop: drop this commit altogether.

In this game, you want to squash cards together into doubles and triples. Some cards make sense on their own, so you will pick them. Sometimes, a card should not even be there, so you might want to drop it.

Although there are other ways of using git rebase, the interactive rebase used like this is a common practice observed in projects that rely on multiple contributors, both in open as well as in closed source. It enables you to commit earlier and with more frequency, because you are able to edit your history before submitting your pull request.

If you'd like a deeper introduction to Git Rebase, please check this great dev article from @maxwell_dev:

Discussion

pic
Editor guide
Collapse
aptituz profile image
Patrick Schönfeld

One of the most useful things I learned for my workflow is git commit —fixup - because often enough I know in advance what is just a correction of a previous commit. I can then automatically cleanup history with git rebase —autosquash.

Collapse
nikoheikkila profile image
Niko Heikkilä

I can recommend rebasing when working in a team. Keeps the history so much cleaner!

Additionally, in my team, we use a lot of fixup (squash the commit but keep the message) and reword (change the commit message but keep the content) when doing interactive rebasing. Both are very valuable prior to push or merge.

Collapse
jwp profile image
John Peters

What's the difference between rebase and merge with master?

Collapse
nikoheikkila profile image
Niko Heikkilä

Atlassian has this covered better than I could put in words. Read on!

Collapse
sgharms profile image
Steven G. Harms

Great example case, cards in a deck. There are some card games that have that play dynamic (flavors of gin rummy, as we call it here in the US) let you take a card in the "stack" but you have to take all the cards on top of it.

Collapse
realtoughcandy profile image
Collapse
richardeschloss profile image
Richard Schloss

Cool! You did this! I didn't think anyone would pay attention to my comment last time :) (and I'm glad you support squashing commits!)

Collapse
bmitchinson profile image
Ben Mitchinson

Amazing!

Collapse
lilislilit profile image
Савельева Елена

Amazing! Thank you!

Collapse
jwp profile image
John Peters

Thanks for post Ericka.

Collapse
raulismasiukas profile image
Raulis Masiukas

Great contribution, thanks!

Collapse
kathryngrayson profile image
Kathryn Grayson Nanz

super cute comic!! and good info

Collapse
erikaheidi profile image
Erika Heidi Author

Thank you! 🤗