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.
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
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.
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_HEADandREBASE_HEADdisappear when the operation finishes or is aborted. Ifgit statussays you are still merging, one of them is still there. Use the command's--continueor--abortrather than deleting files. ORIG_HEADis 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), notrefs/, andgit for-each-refdoes not list them. You can read them withgit rev-parseorgit show. FETCH_HEADformat. Each line is<id> TAB <flag> TAB <description>. Scripts that need the fetched tip should prefergit fetchfollowed bygit rev-parse FETCH_HEADfor the first line, or named remote-tracking refs for stable behavior.- Names are case-sensitive. Write them in upper case;
MERGE_HEADalso resolves on case-insensitive systems butmerge_headis not portable. - Recovery. After an accidental
git reset --harduseORIG_HEADif it is fresh, or the reflog (git reflog) for older states.