Replay private work

Lesson 25 of 25 · Git: records, branches, and collaboration

A rebase can place private work after a newer base. It is not a fix for a bad file or a substitute for a revert. Imagine that main and feature diverged at B:

Before:  A──B──C  main
             └──D──E  feature
After:   A──B──C  main
                └──D′──E′  feature

With feature checked out, git rebase main selects eligible feature commits and reapplies their changes on the current local main. D′ and E′ are new commits with different parents and normally different IDs. main does not move. Git may omit changes already present or pause for conflicts; the replay is not guaranteed to reproduce the original result exactly. A merge instead combines histories without rewriting the existing commits; when histories diverge it can create a two-parent merge commit. A fast-forward can move the receiving branch without one. Follow the project’s policy, and choose merge if preserving the existing identities is important.

For a clean, private feature branch in a disposable repository, inspect the graph and the intended base first:

git status
git log --oneline --graph --decorate --all
git switch feature
git rebase main

The local main is not automatically up to date with a remote; fetch and inspect the relevant remote state first when currency matters. Before replaying, back up needed uncommitted work independently and, if useful, save the committed tip with an unused backup branch. Do not rebase commits others may depend on merely because the branch has your name. Coordinate any agreed rewrite; do not automatically force-push.

If Git stops

A conflict means Git cannot decide how changes fit. git status identifies unmerged paths. A text conflict may look like this; labels and an optional base section vary:

<<<<<<< HEAD
Color: blue
=======
Color: green
>>>>>>> feature-change

During rebase, HEAD is the current replay base and the other side is the commit being replayed; do not assume those labels mean the same branch roles as in a merge. Open each file, decide the intended content, remove markers, and stage the result with git add <path>. Then git rebase --continue resumes; an editor may open, and another commit may conflict. Inspect and test the final result. git rebase --abort instead attempts to return to the pre-rebase state while the operation is in progress; pre-existing edits can complicate recovery. Do not use --skip just to get past a conflict: it omits that commit from the replay.

Reflog can sometimes identify the earlier committed tip after a completed rebase, but it is not a guarantee; see recovery limits.