Skip to content
Latchkey

git rebase: Usage, Options & Common CI Errors

git rebase moves your commits on top of another base, rewriting them as new commits.

Rebase produces a linear history but rewrites commit SHAs, so a rebased branch needs a force push.

What it does

git rebase reapplies your branch commits one by one onto a new base commit, creating new commits with new SHAs. Conflicts pause the rebase until resolved.

Common usage

Terminal
git rebase main
git rebase -i HEAD~3            # squash/reorder last 3 commits
git rebase --onto main old new
# after fixing a conflict:
git add <file> && git rebase --continue
git rebase --abort

Options

FlagWhat it does
-i / --interactiveEdit, squash, drop, or reorder commits
--onto <newbase>Rebase a range onto an arbitrary base
--continueProceed after resolving a conflict
--abortRestore the original branch state
--autosquashApply fixup!/squash! commits automatically

Common errors in CI

CONFLICT … "Resolve all conflicts manually, mark them as resolved with git add, then run git rebase --continue" - the rebase halts mid-way. After rebasing, a push is rejected as non-fast-forward; you must git push --force-with-lease. Interactive rebase needs a non-interactive editor or sequence in CI (e.g. GIT_SEQUENCE_EDITOR).

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →