Git Reference ยท Files and Formats
The .git directory
Reference for the .git directory: HEAD, config, index, objects, refs, hooks, info, logs, packed-refs, ORIG_HEAD and other files and what each one stores.
Everything Git knows about a project lives in one directory, usually .git at the top of the working tree. Delete it and the folder is just files again; copy it and you have copied the whole history. A bare repository is the same set of files placed directly in the repository folder, with no working tree beside it.
Knowing the layout helps when something goes wrong: you can see why a branch exists (a file under refs/heads), where your stash is (refs/stash), why a merge is still in progress (MERGE_HEAD), or how big the object store has grown.
.git/ HEAD config index description objects/ refs/ hooks/ info/ logs/ packed-refs ORIG_HEAD FETCH_HEAD MERGE_HEAD ...
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.
Syntax
The layout is a convention rather than a command, so this section lists what each entry is.
| Entry | Purpose |
|---|---|
HEAD |
Current branch (ref: refs/heads/main) or, when detached, a raw commit ID. |
config |
Repository-level configuration. |
description |
Name for GitWeb; unused elsewhere. |
index |
The staging area, a binary file. |
objects/ |
The object database: loose objects in xx/yyyy... files, plus pack/ (packfiles and indexes) and info/. |
refs/ |
heads/ (branches), tags/, remotes/, plus stash and other special refs. |
packed-refs |
Refs compacted into one file by git pack-refs and git gc. |
logs/ |
Reflogs: logs/HEAD and one file per ref. |
hooks/ |
Executable hook scripts; *.sample files are templates. |
info/ |
exclude (local ignore rules), attributes and sparse-checkout. |
ORIG_HEAD, FETCH_HEAD, MERGE_HEAD, CHERRY_PICK_HEAD, REVERT_HEAD |
Temporary pointers written by commands. |
COMMIT_EDITMSG, MERGE_MSG |
The last or pending commit message. |
rebase-merge/, rebase-apply/ |
State of a rebase or git am in progress. |
worktrees/, modules/ |
Data for linked worktrees and submodules. |
shallow |
Boundary commits of a shallow clone. |
Edge cases: with the reftable ref format, refs/ holds only a stub and the real data is in reftable/. In a bare repository there is no .git folder: these files sit at the top.
Usage notes
- Never edit by hand while Git runs. Prefer plumbing commands (
update-ref,symbolic-ref,config) so locks and reflogs stay correct. - Lock files (
index.lock,HEAD.lock,refs/heads/x.lock) mean a Git process is working or crashed. Remove one only after confirming nothing runs. - Backups are copies of this folder, but copy it with no Git process running.
GIT_DIRmakes Git use another directory;.gitcan also be a file that points elsewhere, see .git file and commondir.- Size.
objects/dominates; rungit count-objects -vHto see loose and packed sizes, andgit gcto compact. - Not versioned. Hooks, local excludes and config in
.gitare never pushed. - Loose object path. The first two hex digits of the ID are a folder, the rest the file name.