Sub topic 2
Reading `update-ref` Lines in the Todo List
Assume you know git switch, git commit, git log, single-branch rebasing, and remote branches. You also need Git 2.38 or newer.
When you run an interactive rebase with --update-refs, Git adds update-ref lines to the todo list. Each line identifies a local branch whose commit is being rewritten.
pick 1a2b3c4 Add parser skeleton
update-ref refs/heads/feature-1
pick 5d6e7f8 Add parser tests
pick 9a8b7c6 Wire parser into CLI
update-ref refs/heads/feature-2
pick 0f1e2d3 Document CLI flagGit moves feature-1 after replaying its last commit. It moves feature-2 after replaying its last commit. The lines preserve the boundaries in the branch stack.
You can remove an update-ref line if you do not want Git to move that branch. Avoid changing the reference name unless you understand the result. The branch may then point to an old commit while the rest of the stack moves forward.
Making `--update-refs` the Default
Set the configuration once:
git config --global rebase.updateRefs trueFuture rebases use the option automatically. Use --no-update-refs for a single exception:
git rebase --no-update-refs mainWhat `--update-refs` Does Not Touch
The option updates suitable local branch references. It does not update a branch checked out in another worktree. It also does not update remote branches. Tags and remote-tracking references are not substitutes for local branch pointers.
Check the result before pushing:
git show-ref --heads
git log --oneline --decorate --graph main..feature-3Pushing the Rebasing Stack Safely
Rebasing creates new commit IDs, so each rewritten remote branch needs a forced update. Push all stack branches with --force-with-lease:
git push --force-with-lease origin feature-1 feature-2 feature-3--force-with-lease refuses to overwrite a remote branch that changed since your last fetch. Review the branch list and fetch first so the lease uses current information.
Exercise
Why can a stack rebase require force-pushing more than one branch?
Show answer
Rewriting commits changes the IDs of every branch built on those commits, so each affected remote branch must be updated.