History rewriter. Powerful. Don't rebase what you've already pushed.
Replay commits onto a different base. Result: a linear history where your commits appear to have been written on top of the new base. Powerful. Rewrites SHAs. Don't rebase what you've already pushed unless you and your team are on the same page.
Rebase finds the commits unique to your branch (base..HEAD), saves them as patches, resets your branch to the new base, and re-applies the patches one by one. New commits, new SHAs. Conflicts can interrupt; resolve and git rebase --continue.
git rebase [-i | --interactive] [<options>] [--exec <cmd>]
[--onto <newbase>] [<upstream> [<branch>]]
git rebase (--continue | --skip | --abort | --quit | --edit-todo | --show-current-patch)| Flag | What it does |
|---|---|
-i, --interactive | Edit the rebase plan: pick, reword, edit, squash, fixup, drop. |
--onto <newbase> | Replay commits onto <newbase> instead of <upstream>. Lets you rebase a slice. |
--autosquash | Auto-arrange fixup!/squash! commits. |
--autostash | Stash dirty changes before rebasing. |
--continue | Resume after resolving conflicts. |
--abort | Restore pre-rebase state. |
--exec <cmd> | Run <cmd> after each commit during rebase. Great for tests-per-commit. |
edit + git reset + multiple commits).$ git fetch origin
$ git rebase origin/main$ git rebase -i HEAD~5$ git rebase --onto target-branch old-base feature$ git rebase --exec 'make test' origin/main--autostash and --autosquash globally: git config --global rebase.autoStash true rebase.autoSquash true.--force-with-lease. Always.main, release/*).--continue, hit another conflict, repeat. Long rebases get tedious — consider merge instead.git commit without --continue can leave you in a confusing state.Hit each option, then Check answers. Score is recorded; Next is always open.