Skip to content
Foxipa

Suggest an edit

Tell us what should be corrected, clarified, or improved. Submission will be connected to Foxipa’s contribution service later.

No information is sent anywhere yet. Your suggestion is only prepared in your browser.

Learning

Git Rebase: Running, Controlling, and Verifying History Rewrites

Use git rebase in controlled workflows: choose a base, transplant commits, handle the in-progress operation controls, and verify the resulting local history.

Levels: Advanced ~40 min read

Advanced

Run a basic rebase

With a topic branch checked out, `git rebase main` takes the commits selected relative to `main` and replays them on the tip of `main`. The operation changes the local topic branch; it does not publish anything to a remote.

bash
git switch topic
git rebase main
git log --oneline --graph --decorate --all

Quick check

What does `git rebase main` do in the common case?

The topic branch contains commits not reachable from main.Those commits are replayed on top of main.

Use --onto when the comparison boundary and new base differ

`--onto <newbase> <upstream> <branch>` separates the commit-selection boundary from the place where the new commits are created. This is useful when a branch contains a stack and only the commits after an intermediate branch should be transplanted.

bash
git rebase --onto main server client
# equivalent shape: commits after server on client are replayed onto main

Quick check

What does `--onto` add to the rebase model?

The branch has commits after an intermediate upstream.Those selected commits can be created on a different new base.

Rebase may accept an explicit branch to operate on

The normal form operates on the current branch. The three-argument form can name the branch explicitly: `git rebase <upstream> <branch>`. Git switches to the named branch as part of the operation. This is useful for controlled repository automation, but the lesson's main labs keep the target branch checked out so the state transition is visible.

bash
git rebase main topic
git rev-parse --abbrev-ref HEAD
git rev-parse topic

Quick check

What is special about `git rebase main topic`?

A topic branch exists but another branch is checked out.The named topic branch is the branch being rebased.

A rebase can stop before completion

If replaying a commit cannot complete cleanly, rebase stops at the problematic commit and leaves an in-progress rebase state. At that point the operation has not finished. `git status` reports the state, and `git rebase --show-current-patch` can show the patch currently being applied. Resolution and continuation are covered in the later rebase-conflict ownership boundary.

bash
git status
git rebase --show-current-patch
# later: git rebase --continue
# or: git rebase --abort

Quick check

What does a stopped rebase mean?

Replay cannot complete at the current commit.The repository remains in a rebase state until that state is resolved or abandoned.

--abort restores the pre-rebase branch state

`git rebase --abort` abandons an in-progress rebase and resets the branch back toward the state from which that rebase started. This is a recovery control for an active rebase, not a general substitute for `git reset` or `git revert`.

bash
git rebase --abort
git status --short --branch
git rev-parse HEAD

Quick check

What is the purpose of `git rebase --abort`?

A rebase is currently in progress.The rebase state is abandoned and the original branch state is restored.

--skip changes the replay sequence

`git rebase --skip` abandons the current problematic patch and resumes the rebase with the remaining sequence. It therefore changes which commits are replayed into the resulting history. It should be treated as an explicit history decision, not as a generic conflict-resolution shortcut.

bash
git rebase --skip
git status --short --branch
git log --oneline --graph --decorate --all

Quick check

What does `git rebase --skip` do during an in-progress rebase?

The rebase is stopped on a current patch.Git proceeds without replaying that patch.

Verify the resulting state instead of trusting output

After a successful rebase, verify the branch tip, parent relationship, selected base, and working-tree state. For a non-empty replay onto an advanced base, the new tip normally has a different object ID from the old tip and descends from the new base. The remote remains unchanged until a separate push.

bash
old=$(git rev-parse topic)
base=$(git rev-parse main)
git rebase main
new=$(git rev-parse topic)
printf 'old=%s\nbase=%s\nnew=%s\n' "$old" "$base" "$new"
git merge-base --is-ancestor "$base" "$new"
git status --short --branch

Quick check

Which checks directly establish a successful non-empty rebase?

The old tip and selected base are recorded.The new tip is compared with the old tip and checked for ancestry.

Practice what you learned

Use the dedicated Git code-completion exercise for this lesson.

Was this page helpful?

Mark this learning resource complete to track your learning progress.