About git rebase helper
Rebase replays your commits on top of another branch, giving a straight, tidy history. Interactive rebase lets you squash, reorder and edit commits.
The golden rule
Do not rebase commits that others already have. Rebasing rewrites history, so use it on your own branches before merging.
If something goes wrong
- git rebase --abort returns you to the state before the rebase.
- git rebase --continue after fixing conflicts.
- git reflog to recover lost commits.
A worked example
Your feature branch is three commits behind main. Run git switch feature, then git rebase main. If a conflict appears, fix the files, git add them and run git rebase --continue. To tidy five messy commits into one, use git rebase -i HEAD~5 and mark the later ones as squash.
After rebasing
Your branch history has changed, so pushing needs git push --force-with-lease. That is safer than --force, since it refuses to overwrite work that you have not seen.
