Skip to content
Tutorials Center
My learning

Topics

Git Reference ยท Objects, Refs and Internals

Special refs

Reference for Git's special refs: ORIG_HEAD, MERGE_HEAD, FETCH_HEAD, CHERRY_PICK_HEAD, REVERT_HEAD, REBASE_HEAD and others, who writes them and how to use them.

Besides branches and tags, Git keeps a handful of upper-case files directly in .git/: ORIG_HEAD, FETCH_HEAD, MERGE_HEAD, CHERRY_PICK_HEAD and a few more. They are not branches. Git creates them as side effects of commands to remember a commit it may need again, for example the tip you had before a risky operation, or the commit being merged while you resolve conflicts.

Knowing them helps in two ways: you can use them as revision names (git reset --hard ORIG_HEAD), and a leftover file tells you that an operation is still in progress.

Terminal
git diff ORIG_HEAD HEAD     # what the last merge, pull or reset changed
git log HEAD..FETCH_HEAD    # what a fetch brought in
git rev-parse MERGE_HEAD    # the commit being merged (during a merge)

Try it

Bash ORIG_HEAD: undo a merge or reset

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash MERGE_HEAD, CHERRY_PICK_HEAD and FETCH_HEAD

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

The special refs

Name Written by Meaning
ORIG_HEAD merge, pull, rebase, reset The value of HEAD before a command that moves it drastically. Use it to undo.
FETCH_HEAD fetch, pull The tips fetched by the last fetch, one per line in .git/FETCH_HEAD, with a "not-for-merge" marker for refs that pull would not merge.
MERGE_HEAD merge The commit(s) being merged while the merge is unfinished. One per parent beyond the first (octopus merges have several lines).
CHERRY_PICK_HEAD cherry-pick The commit being picked, kept until the pick is committed or aborted.
REVERT_HEAD revert The commit being reverted, while a conflict is open.
REBASE_HEAD rebase The commit that was being applied when a rebase stopped.
BISECT_HEAD bisect --no-checkout The commit currently being tested.
AUTO_MERGE merge A tree recording what Git merged automatically, so git diff AUTO_MERGE shows only your conflict resolution (Git 2.42+).
MERGE_AUTOSTASH merge --autostash The ID of the temporary stash made before the merge, applied again when it finishes.

Files like MERGE_MSG, MERGE_MODE, SQUASH_MSG and COMMIT_EDITMSG are not refs: they hold the prepared commit message or state flags.

Usage notes

  • Transient by design. MERGE_HEAD, CHERRY_PICK_HEAD, REVERT_HEAD and REBASE_HEAD disappear when the operation finishes or is aborted. If git status says you are still merging, one of them is still there. Use the command's --continue or --abort rather than deleting files.
  • ORIG_HEAD is overwritten by the next command that sets it. If you need the value for later, copy it to a branch: git branch backup ORIG_HEAD.
  • They are pseudo-refs. They live in .git/ (per worktree), not refs/, and git for-each-ref does not list them. You can read them with git rev-parse or git show.
  • FETCH_HEAD format. Each line is <id> TAB <flag> TAB <description>. Scripts that need the fetched tip should prefer git fetch followed by git rev-parse FETCH_HEAD for the first line, or named remote-tracking refs for stable behavior.
  • Names are case-sensitive. Write them in upper case; MERGE_HEAD also resolves on case-insensitive systems but merge_head is not portable.
  • Recovery. After an accidental git reset --hard use ORIG_HEAD if it is fresh, or the reflog (git reflog) for older states.