On This Page
What Is the .git Folder?
Quick Answer: The .git folder is the repository. Every commit you’ve ever made, every version of every file, all branches and tags, and your entire configuration are stored inside this one hidden directory. The files and folders you see in your project are just a checkout — a working copy of one specific snapshot that Git pulled out of the .git database.
⚠️ Two rules before we go further: never delete
.git/unless you want to permanently destroy all history, and never put.git/inside another project’s zip or commit — each repo has exactly one, at the project root.
Why Is There a Hidden .git Folder at All?
When you run git init, Git creates a regular directory plus a hidden subdirectory named .git. The name is deliberate — a leading dot keeps it out of sight on macOS/Linux (ls -a reveals it), and out of your way while you work.
Everything you consider “Git” actually lives here:
$ mkdir demo && cd demo
$ git init
Initialized empty Git repository in /home/you/demo/.git/
$ ls -F1 .git/
HEAD
config
description
hooks/
info/
objects/
refs/
Once you stage your first file, a new entry appears — the index:
$ echo "hello" > README.md
$ git add README.md
$ ls -F1 .git/
HEAD
config
index ← appeared after git add
objects/
refs/
...
What Each Thing Inside .git/ Does
| Entry | What it is |
|---|---|
HEAD | A tiny text file saying which branch or commit is currently checked out — usually contains ref: refs/heads/main. Detailed in /git-refs. |
index | The staging area as an actual file: the list of exactly what goes into your next commit. That’s all git status compares. |
objects/ | The heart of Git — every blob (file content), tree (directory), commit, and tag, stored by its SHA-1 hash. Fully dissected in /git-objects. |
refs/ | Branches and tags as simple text files pointing to commit hashes (refs/heads/main, refs/tags/v1.0). Also in /git-refs. |
config | Repository-specific settings: your remote URLs, branch tracking, local user identity. Explained in /git-config. |
hooks/ | Scripts Git runs automatically around events like commits or pushes. Covered in /git-hooks. |
info/exclude | A private per-repo ignore list, like .gitignore but never shared. |
logs/ | Reflog — a journal of every move HEAD and your branches have made. Your undo safety net. |
That’s the entire trick behind Git: your project’s full timeline is just files in a folder — compressed content addressed by hashes (objects/), plus tiny pointer files (refs/, HEAD). Commands like commit or branch don’t do anything magical; they write and rearrange these small text entries. Watch it happen command-by-command in /git-init, /git-add, and /git-commit.
▶ See it live: open the interactive playground and run
init,add, andcommit— the.gitfolder builds up in front of you, object by object.
Can You Delete the .git Folder?
Yes, physically — but you lose everything Git-related, instantly. Deleting .git/ removes:
- All commits and their messages
- All branches and tags except the files currently on disk
- Your staging area and reflog
Your current files survive (they’re plain files), but the project stops being a repository. The only realistic reasons to do this intentionally:
- “Un-Git” a project — you inherited code with history you’re not allowed to keep. Delete
.git/, optionally rungit initfor a fresh start. - Fix a repo created in the wrong place — same: remove
.git/, re-init where it belongs.
If you only want to undo recent work, don’t touch .git/ — use git reset vs revert vs checkout instead; they surgically rewind without nuking anything.
Common .git Folder Questions
Is it safe to copy or email a project folder that includes .git?
Safe, yes — but heavy (it holds all history) and it leaks everything ever committed, including secrets that were deleted later. Use git clone or a clean export instead.
Why does my cloned repo have .git but my downloaded ZIP doesn’t?
GitHub’s “Download ZIP” gives you only the snapshot — no history, no repository. Clone to get the real thing with .git/ included.
Can I put .git somewhere else?
Yes, via the GIT_DIR environment variable or git --git-dir=..., but there’s rarely a reason to. Keep it simple: one .git at the project root.
Go Deeper
Each piece of .git/ has a full interactive lesson:
git init— how the folder is borngit objects— blobs, trees, commits, and tags insideobjects/git refs— how branches and tags are just pointerspackfiles— how Git compresses loose objects over time
Or experiment freely in the playground — nothing there can break your machine.