DEV Community

Explain Git Rebase just like I'm five

Theofanis Despoudis on September 28, 2017

Git rebasing is a good example for teaching 5-year-olds when they start coding as they can work on something more complex. Explain!

Collapse
 
maxwell_dev profile image
Max Antonucci

I actually wrote a git rebase introduction on this site recently, please check it out!

dev.to/maxwell_dev/the-git-rebase-...

Collapse
 
nuc profile image
Georgios Giannoutsos Barkas

Let's say that you want to make a lego building.

First, you get the base plate and then you start building multiple floors on top of it.

You build three floors with apartments.

Your sister comes along and builds a really nice bicycle store right next to you, on the same base plate.

You suddenly realise that you'd love your building to have a bicycle store (ofc). Instead of building one, why not to combine both buildings?

So, you first ask your sister and then you carefully remove the floors of your building one at a time, and you place them on top of the bicycle store, first the first floor, then the second floor, and so on.

That's rebasing :)

Collapse
 
pratikaambani profile image
Pratik Ambani

Awesomely explained, I've a doubt, who will decide on which floor this bicycle store would be located??

Will it be on the same floor in new building where the bicycle store was built in other building??

Collapse
 
nuc profile image
Georgios Giannoutsos Barkas

Rebase will find the common ancestor (the lego base plate) and split your branch (the building without the bicycle store) from there.

It will point the head to the tip of the other branch (top level of the building with the bicycle store) and will replay all your commits on top of that.

Thus, the bicycle store, along with all other levels of that building, will stay where they were first built.

I hope that's clear :)

Collapse
 
tommyxlos profile image
Thomas Los

That sir, is amazing, so stealing this next time I get that question :). Should add a merge part in there to make it even more golden :)

Collapse
 
srebalaji profile image
Srebalaji Thirumalai

Consider your mom has a drawing and she needs the entire family to contribute to the drawing.

And then the family has got a powerful tool named Git.

So first, her daughter tries to contribute to the drawing by getting a current copy of the drawing. So she spends two days to add some parts to drawing and did some coloring too.

Then she asks her mom to copy the parts of her drawing with the current version of the drawing.

But her mom says that in the past two days her brother and her father have updated some parts of the drawing and the current version of the drawing is not the version she had two days back.

So her mom suggests her to take a current copy of the drawing now and copy the parts of her drawing she did in the older version to the new copy of the drawing.

So in this way the daughter has the current version of the drawing with the parts she did to the drawing. And then now she asks her mom to copy her parts to the current version.

Her mom happily does it. :)

Hope this helps.. :)

Collapse
 
bgadrian profile image
Adrian B.G.

As a 5y old you started alone to build a Wood Wagon specifically for the mars Planet Atmosphere & gravity.

You put aside the wagon after you finish it, because your parents tels you we haven't colonize Mars yet.

After 35 yrs, the wagon is rotten, cannot be used, but you won a ticket to Mars and wait it so bad.

You find this Time Machine and hit the "rebase" button, while whispering "I wish I could bring my Mars Wood Wagon here & now". And Voila!

The Wagon is moved trough the history, and magically rebuilt in front of you. You get your wooden wagon here and now, you pack it and go on Mars with it. The Wagon building steps were erased from the history and you remember as you were building it today, not 35yrs ago.

Now ... I said alone, because if when you were 5y and built the Wagon, one of your friends have helped you, now ... when you moved it trough the history ... something really bad would happen. He will have memories of a thing that didn't existed.

Rebase, like a Time Machine is very powerful, should not be used lightly.


Disclaimer: I recommend NOT to use rebase for many reasons, try git merge --squash if you want this effect, but the history should remain as it was, not as we want, we should learn from history.

Wood Wagon - your commits on an old branch, put on hold while others developed the master. You want to bring the branch in a newer master.
5y Kid - you as developer
World - the repository
Time - commit order (A-B-C-D) in git history log
Friend - developer who helped you on that branch, and want to continue. You have to rebase --force your timeline into his, erase his memories too.

Collapse
 
rysilva profile image
Ryan Silva • Edited

I just decorated a cake for your party. But after I finished, you told me you decided the cake was chocolate, instead of vanilla. So I removed the candles, the lettering, and the frosting. Then I redid the frosting, the lettering, and candles on the chocolate cake.

Now I just hope that I never sent anyone a copy of that first cake, and that nobody added any more decorations to it!

Collapse
 
andy profile image
Andy Zhao (he/him) • Edited

Yet another @maestromac topic.

Or maybe @gonedark ?

Collapse
 
leonpelech profile image
Leon Pelech • Edited

You're playing in the sand pit with a friend and decide to both build sandcastles. You build your sandcastle and have a flag which you put in the top. Your friend does the same and sticks a flag in hers. It's pretty cool!
You think that it would be even cooler if you could have your castle on top of hers but you can't lift yours up without it crumbling. Instead, you build an identical castle ontop of hers and put both your flags in the top.
Now you have a mega sand castle with your friends at the bottom and a copy of yours on top. Your original castle is still there but you won't build on it anymore.

Sand pit = repo
Flag = branch/HEAD
Castle = commits

Collapse
 
datamafia profile image
data['mafia'] = True

because I said so.