Rebase a Private Feature Branch Safely
Prepare a clean private branch
Use the chapter fixture with main and feature diverged, two independent feature commits, and no remote. In a real project first check team policy, branch publication and git status. Save uncommitted work separately; a rescue branch preserves commits only. If another developer already depends on the branch, prefer merging or coordinate before rewriting.
git switch featuregit status --shortgit log --graph --oneline --allgit branch rescue-featureReplay and verify
Run the next block only if status is clean and rescue-feature was created successfully. The explicit --no-autostash and --no-update-refs flags avoid automatic stashing and moving other branch references. The example uses Git 2.47.3. On success main is an ancestor of feature, the old feature tip remains at rescue-feature, and README, water.txt and light.txt all exist. A conflict requires the next lesson; do not blindly repeat the command.
git rebase --no-autostash --no-update-refs maingit log --graph --oneline --allgit merge-base --is-ancestor main featuregit status --shortCompare the series and integrate
Range-diff compares two versions of the feature patch series. Resolve the old common ancestor while main still points to the new base, then compare both explicit ranges. This is a human review aid, not proof of semantic equivalence.
base=$(git merge-base main rescue-feature)git range-diff "$base..rescue-feature" main..featurePractice and fast-forward
Verify all three files and compare original and replayed parents in the report. In the clean fixture only, switch to main and fast-forward; main moves to feature without creating a merge commit. If main advanced again, stop and inspect.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Rebase a Private Feature Branch Safely — knowledge check
Reason about safe rebase and history integration.
What must be checked before private rebase?
What does a rescue branch preserve?
Which command checks whether main is an ancestor of feature?
What does range-diff help review?
What does ff-only do after a successful private replay and unchanged main?