Your .git folder is public — and that is a full source-code download
Why .git is so dangerous
The .git folder is the entire repository: every file, every version, every commit message, every author. Git keeps all of it locally so you can check out any past state. That is wonderful on your machine — and catastrophic on a public web server, because if /.git/ is reachable, an attacker can pull the whole thing down and rebuild your codebase as it exists and as it existed.
That history part is the sting. A secret you committed in a panic six months ago and removed the next day is still in the history. Remove it from the current files all you want — git remembers, and so does anyone who downloaded your .git.
How it gets exposed
The usual cause is deploying by copying the project directory — including its hidden .git folder — straight into the web root, then serving that folder without blocking dotfiles. Now requests like /.git/config and /.git/HEAD return real git data instead of a 404, and that is all an attacker needs to start.
How it is exploited
The attacker does not need your server to allow directory listing. Git's internal structure is predictable, so automated tools walk it file by file: read /.git/HEAD, follow it to the index and the object store, fetch each object, and reassemble the working tree. Within seconds they have your source. Then they grep the history for keys, passwords and tokens — the things that get committed by accident and are assumed gone.
How to tell if you are exposed
Request /.git/config or /.git/HEAD on your own site. If you get back text that looks like git internals — [core], repositoryformatversion, a ref like ref: refs/heads/main — your repository is downloadable. A 404 or a block is what you want to see.
How to close it
- Do not deploy the
.gitfolder. Build and ship only the artifacts you need, not the repository. A clean build pipeline never copies.gitto production. - Block all dotfiles at the server. Deny any path starting with a dot, so a stray
.gitstill cannot be read. - Rotate secrets if it was reachable. Assume anything ever committed — including in old, deleted history — is now known, and rotate it.
- Scrub the history if needed. For genuinely sensitive commits, rewriting history removes them from the repository going forward, but treat already-exposed secrets as burned regardless.
Confirm it on your site
A public .git folder is invisible until someone requests the right path — so request it yourself. An automated scan checks /.git along with the other high-value leaked-file paths and tells you exactly what answers. Scan your site and make sure your source is not for download.