Skip to content

Rebase

In one line

Rebasing replays your branch's commits on top of another branch, creating a linear history without merge commits.

In simple words

git rebase takes the commits from your current branch and replays them one by one on top of another branch (e.g. main). The result is a straight line of commits — as if you had started your work from the latest main.

Rebase produces cleaner, linear history because it does not create merge commits. However, it rewrites commit hashes, which means anyone who has already pulled your branch will have divergent histories. The golden rule: never rebase branches that others have already pulled.

Use rebase for local feature branches to keep them up to date with main. Use merge for shared branches to preserve history and avoid rewriting commits others depend on. If a rebase hits conflicts, resolve them and run git rebase --continue, or git rebase --abort to cancel.

Example

bash
# Rebase feature onto latest main
git checkout feature
git rebase main

# Interactive rebase to squash commits
git rebase -i main

Rebase replays feature commits on top of main for linear history.

Common confusions

  • Confused with: merge

    The difference: Merge combines branches and creates a merge commit, preserving branch history. Rebase replays commits on top of the target, producing linear history but rewriting hashes. Merge is safe for shared branches; rebase is for local cleanup.

Related terms

Related Resources

Related Lessons

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary