Like so many others who watch daily at my proverbial door for the next golden drop of Git wisdom to fall from my gilded lips, you've probably been waiting with breathless anticipation for me to talk about rebasing. (Or you're just here because you saw 'git rebase' in the title and you're curious--I suppose anything is possible.)
In any case, your interest is understandable. There are few Git skills at once more fundamental and less understood than rebasing. And no wonder, really--it's basically magic, and magicians don't readily give up their secrets.
I've Googled hard, but I've sought in vain a good diagram that shows what's actually going on behind the scenes. Let's fix that, shall we?
Join me now, as we embark on a perilous journey to understand Git rebase, armed with nothing but a terminal and a dream...
First, we clone a repository for local development.
(you) $ git clone [remote]
Then we create a feature branch to work on a new issue.
(you) $ git checkout -b feature
We do some work and commit our changes.
(you) $ [code, commit, etc.]
But in the meantime, the upstream repository commits changes, too. Now we've diverged.
(you) $ git fetch [remote]
Time to rebase.
(you) $ git rebase main
Under the hood, Git creates an invisible working branch and checks it out, putting us into a kind of magical in-between state.
(git fairies) $ git checkout -b REBASE main
Then it begins to 'replay' the commits on the new branch. It finds the first one we have that our base branch doesn't and cherry-picks it.
(git fairies) $ git cherry-pick [A]
If there are merge conflicts, it stops and asks us to resolve them.
Once we do, we hand it back to Git to continue the process.
(you) $ git rebase --continue
It proceeds to the next commit and cherry-picks it.
(git fairies) $ git cherry-pick [B]
If there are merge conflicts again, it stops and asks us to resolve them, just like before.
And, just like before, we do so and hand it back to Git to continue.
(you) $ git rebase --continue
The process continues until all of our commits have been copied over.
(you and the fairies) $ [...]
Once it's finished, it overwrites our feature branch with the result and returns us to it.
(git fairies) $ git branch --force feature
Then it deletes the hidden REBASE branch.
(git fairies) $ git branch -D REBASE
And we're done! Our commits now start from the current tip of the base branch, as if we had branched from there to begin with. Go ahead: take a bow.
If this content did not answer your questions, try searching or contacting our support team for further assistance.
Fri Sep 12 2025 06:30:47 GMT+0000 (Coordinated Universal Time)