While you worked on feature/faq, main moved on. Merging would add a merge commit. Rebase does something else: it replays your commits, one by one, on top of main's latest commit, as if you'd started there.
git log --oneline --graph --all
* 8dcb9a9 (main) Add a banner
| * 42856d9 (HEAD -> feature/faq) Answer more questions
| * 737795e Add a FAQ
|/
* 707f8ea Start the shop
git rebase main
Successfully rebased and updated refs/heads/feature/faq.
git log --oneline --graph --all
* 565d2d8 (HEAD -> feature/faq) Answer more questions
* 69562b7 Add a FAQ
* 8dcb9a9 (main) Add a banner
* 707f8ea Start the shopThe history is a straight line now, but look at the hashes: 737795e became 69562b7. Rebase can't move a commit. It makes new copies with new parents, so they get new hashes. The originals fade to ghosts on the graph.
That's why the golden rule of rebasing is: only rebase commits you haven't pushed. Anyone who already has the old copies would end up with both.
Rebase moves the branch you're on, and only that branch. Run it from your feature branch, naming the branch to replay onto.
Rebased the wrong branch? A rebase writes several lines in git reflog, so HEAD@{1} isn't where you were. Take the hash on the line just below rebase (start) and git reset --hard to it.
Objectives
- Move your branch onto the latest
main. - Leave
mainalone. - Bring search into
mainwithout a merge commit.