Git Rebase
git rebase takes the commits on your branch and replays them, one by one, on top of another branch. The result is a straight line of history, with no merge commit.
Rebasing creates new commits with new hashes. Do not rebase commits that you have already pushed and others use.
Rebase a feature branch onto main
main got a new commit after new-feature was created. Move new-feature on top of it:
git switch new-feature
Switched to branch 'new-feature'
git rebase main
Successfully rebased and updated refs/heads/new-feature.
git log --oneline --graph
* de214e8 Add blue style
* 5e4276a Update README
* 5740ce0 Add README
* f132bf3 First release of Hello World!
Interactive Rebase
git rebase -i HEAD~3 opens the last 3 commits in your editor, so you can reorder, edit, drop or squash them before they are replayed.
If a rebase stops with a conflict, fix it, git add the file and run git rebase --continue, or go back with git rebase --abort.