Sub topic 5
Reading update-ref lines in the todo list
This chapter assumes you can run git rebase -i on a single branch and edit its todo list. It also assumes you have a stack of branches like the one built earlier in this tutorial, and Git 2.38 or newer. Here you will learn what the extra lines in the todo list mean, how Git uses them, and what happens when you edit, move, or delete them.
Where the lines come from
Interactive rebase works from a todo list. Each line is a command such as pick, reword, or squash, and Git runs the lines from top to bottom. When you add --update-refs, Git scans the commits being rebased. If a local branch points at one of them, Git inserts an update-ref line right after that commit's pick line.
Take a stack where feature-1 holds one commit, feature-2 adds two more, and feature-3 adds one more. You are on feature-3. This command opens the todo list:
git rebase -i --update-refs origin/mainThe editor shows lines like these. The commit IDs are examples, and yours will differ.
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 flagfeature-3 has no update-ref line. A plain rebase already moves the branch you are standing on, so Git only lists the other branches in the stack.
An update-ref line has one argument, the full ref name. The name starts with refs/heads/, not just feature-1. It is a placeholder that means "the branch with this name should end up at this position in the rewritten history."
What Git does when it reaches the line
When Git reaches an update-ref line, it notes the commit that HEAD points at. That commit is the rewritten version of whatever the previous pick produced. Git does not move the branch yet. It keeps the old and new values in its rebase state, in the .git/rebase-merge directory. After the last todo line succeeds, Git moves every recorded branch to its new commit.
This has three practical consequences:
- While the rebase is paused, for example on a conflict,
feature-1andfeature-2still point at their old commits.git log feature-1shows the pre-rebase history until the rebase ends. - If you run
git rebase --abort, no branch has moved, so nothing needs undoing. - Git records each branch's old value. If a branch moves during the rebase, Git reports an error for that ref instead of silently overwriting it.
Seeing the todo list without an editor
You can look at a generated todo list without editing it. Set GIT_SEQUENCE_EDITOR to cat. Git then shows the list and accepts it unchanged. The script below builds a small stack and rebases it onto a main branch that has moved on.
git init -q -b main stack-demo
cd stack-demo
c() { echo "$1" > "$1.txt"; git add "$1.txt"; git commit -q -m "$2"; }
c base "Initial commit"
git switch -q -c feature-1
c skeleton "Add parser skeleton"
git switch -q -c feature-2
c tests "Add parser tests"
c wiring "Wire parser into CLI"
git switch -q -c feature-3
c docs "Document CLI flag"
git switch -q main
c unrelated "Change on main"
git switch -q feature-3
GIT_SEQUENCE_EDITOR=cat git rebase -i --update-refs main
git log --oneline --decorate --graph main..feature-3The cat command prints the todo list, including update-ref refs/heads/feature-1 and update-ref refs/heads/feature-2. The final git log then shows all three branch names on the rewritten commits. Run git log --oneline feature-1 before and after to confirm that the lower branches moved.
You can also run git rebase --update-refs main without -i. Git builds the same todo list internally and runs it without opening an editor. The lines exist in both cases, and only the interactive form lets you change them.
Editing the lines
The update-ref lines are ordinary todo commands. You can edit them like any other line, and each edit has a predictable result.
| Edit | Result |
|---|---|
| Leave the line alone | The branch moves to the rewritten commit above the line. |
| Delete the line | The branch is not moved and keeps pointing at its old commit. |
| Move the line to another position | The branch ends at whatever commit `HEAD` is at when Git reaches the line. |
| Reorder `pick` lines across the line | The branch ends at the rewritten commit just before the line, whichever commit that now is. |
| Add a line for a branch Git did not list | Git moves that branch too. |
Deleting a line is the simplest way to keep one branch out of a restack. For example, you might have a scratch branch that happens to sit in the stack's range. Delete its line and it stays put.
Moving a line lets you split or merge branches. Suppose feature-2 should end one commit earlier. Move its update-ref line up above the pick for Wire parser into CLI:
pick 1a2b3c4 Add parser skeleton
update-ref refs/heads/feature-1
pick 5d6e7f8 Add parser tests
update-ref refs/heads/feature-2
pick 9a8b7c6 Wire parser into CLI
pick 0f1e2d3 Document CLI flagAfter this rebase, feature-2 contains only the skeleton and the tests. The wiring commit now belongs to feature-3 alone. The branch is no longer where it was before, so check that a pull request for feature-2 still makes sense.
You can add a line by hand. Type update-ref refs/heads/some-branch after the commit where that branch should land. This is useful when you create a branch late and want it to follow the stack.
Always write the full ref name. A bare feature-1 is not a valid argument.
Interaction with other todo commands
The update-ref line follows the same rules as the other lines when you restructure history:
- If you
squashorfixupa commit into the one above it, theupdate-refline between them still recordsHEADat that point. Put the line after the squashed commit, not between the two. A line placed between them would record the commit before the squash was applied. - If you
dropthe commit above anupdate-refline, the line records whichever commit is then atHEAD. The branch lands on the previous kept commit. - If you use
edit, the rebase pauses on that commit. Theupdate-reflines already passed are recorded, and the ones after it are still pending. execandbreaklines do not affect the placeholders. You can putexec git log -1 --onelineafter anupdate-refline to print what was recorded, which helps when you check a long list.
What a conflict looks like in the list
If a pick conflicts, the rebase stops there. The lines above it are done, and the lines below it are still waiting. After you resolve the conflict, stage the files and run git rebase --continue. Git then resumes at the next todo line and records any placeholders it passes.
During the pause, git status shows which step you are on and which todo lines remain. You can also read the pending list with:
git status
cat .git/rebase-merge/git-rebase-todoThe second command shows the remaining lines, including any update-ref lines still to come. The full conflict walkthrough comes in a later chapter. For now, remember that an unfinished rebase has not moved any of the lower branches.
Common mistakes
- Expecting the branch to move at once. Git moves the lower branches at the end of the rebase, so mid-rebase
git log feature-1shows old commits. - Using a short name.
update-ref feature-1fails. Useupdate-ref refs/heads/feature-1. - Deleting a
pickand leaving its line. The branch then lands on an earlier commit than you intended. - Assuming the current branch is listed. The branch you started on is never in the list, because the rebase itself moves it.
- Forgetting that remote copies are unchanged. Moving local branches does not update
origin. Pushing comes later in this tutorial.
Exercise
You run git rebase -i --update-refs main on feature-3. The list has update-ref refs/heads/feature-2 after the commit "Wire parser into CLI". You delete that line and finish the rebase. Where does feature-2 point afterwards, and which branches moved?
Show answer
feature-2 still points at its old, pre-rebase commit. feature-3 moved because it was the branch being rebased. feature-1 moved because its line was still in the list. Deleting a line excludes that branch from the update.
Exercise
In the list below, you want feature-1 to include both parser commits. What single edit achieves that?
pick 1a2b3c4 Add parser skeleton
update-ref refs/heads/feature-1
pick 5d6e7f8 Add parser tests
pick 0f1e2d3 Document CLI flag
Show answer
Move the update-ref refs/heads/feature-1 line down so that it sits after pick 5d6e7f8 Add parser tests. Git then records HEAD after the tests commit, so feature-1 ends there and contains both parser commits.
Exercise
Midway through a rebase, a conflict stops Git on the Add parser tests pick. A colleague runs git log --oneline feature-1 in another terminal of the same repository. Do they see the rewritten skeleton commit? Why or why not?
Show answer
No. Git records the new value for feature-1 when it passes the update-ref line, but it moves the branch only after the whole rebase finishes. Until then feature-1 still points at its old commit. If you abort the rebase, it never moves.