GIT / A CONCEPT NOTE

Rebase vs Merge

two ways to combine work

~70 sec read

Overview · mechanism
pitfall · examples

01 / THE SHORT VERSION

The idea in a few sentences.

Merging keeps history unchanged by creating a new merge commit. Rebasing rewrites history by moving your commits onto the tip of the target branch, producing a flat linear timeline.

02 / FOLLOW THE MECHANISM

How rebasing rewrites commits

  1. Work splits

    main branch moves forward with commits while you work on feature-a.

  2. Rebase call

    runs git rebase main. Git shelves your feature commits temporarily.

  3. Base swap

    git updates feature branch base pointer to point to current main head.

  4. Re-apply

    applies feature commits sequentially on top. Commit SHAs are rewritten.

04 / COMMAND NOTES

Read the command, then the result.

Inspect the flags and arguments before trying an example. Snippets can need local setup, replacement values, or resources in your own environment.

EXAMPLE 01 · REFERENCE

rebase current branch commits onto main branch

git rebase main

EXAMPLE 02 · REFERENCE

interactively squash or edit the last 3 commits

git rebase -i HEAD~3

Explore command anatomy in the CLI lab