DEV Community

Discussion on: Explain Git Rebase just like I'm five

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
 
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
 
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 :)