.git folder exposed on my website: how to fix it
Short answer
If yoursite.com/.git/config answers, anyone can download your whole repository, including every old commit and any secret ever committed. Block the folder at the web server, deploy without it, and rotate every key or password that appears anywhere in the history. Closing it only stops new downloads.
Why you got this
The .git folder holds the full project history. It ends up on a server when the site is deployed by copying or cloning straight into the web root, which is common with simple VPS setups and shared hosting. Files in it are served like any other file unless the web server blocks them.
Tools exist that rebuild a repository from an exposed .git folder, so the attacker gets source code, commit messages and every secret that was deleted later. The risk is rarely the folder itself; it is the history it contains.
Typical leftovers are a password in an early commit that was removed later, a database dump added by mistake and an old .env file. None of them is visible on the live site, yet all of them are one download away.
What to do now
Request yoursite.com/.git/HEAD in a private window. If it returns text such as ref: refs/heads/main, the folder is exposed.
Block it with the rules below, or delete the folder from the web directory. Then confirm the URL returns 404 or 403.
Search the history for secrets: database passwords, API keys, tokens and old .env files. Rotate everything you find; deleted files are still in old commits.
Check your hosting and provider logs for unfamiliar access, and review user accounts and recent data changes.
How to fix it properly
In nginx, deny dot paths (this also protects .env and similar files), except the .well-known folder used for certificates.
location ~ /\.(?!well-known) {
deny all;
return 404;
}In Apache, block the folder and dot files.
RedirectMatch 404 /\.git
<FilesMatch "^\.(?!well-known)">
Require all denied
</FilesMatch>Deploy a build artifact, not a repository checkout. Use a CI pipeline, rsync with an exclude for .git, or a platform deploy. In Docker, list .git in .dockerignore so it never enters an image.
Keep the document root on the public folder only, and keep secrets in environment variables, not files that can be committed.
How to check it is fixed
Request /.git/HEAD, /.git/config and /.git/index again. All should return 404 or 403 and no content. Test from outside your network too.
The verified ScanAnt scan, on sites you have proved you own, checks for public .git folders along with .env files, backups and debug pages. The free quick scan covers only public page content. Neither can tell which secrets were in your history, so search it yourself with a tool such as gitleaks.
Questions
Can someone really rebuild my repository?
Yes. Public tools exist for exactly this, and it works when the folder is served openly. That is why history matters.
I only exposed it for a day. Do I still rotate?
Yes. Scanners probe constantly, so a day is plenty of time.
Does a private repository on GitHub protect me?
Not if you cloned it into your web root. The exposure is on your server, not on GitHub.
Should I clean the history?
Rotating secrets is required. Cleaning history is optional and only helps with future copies.
Related checks
Check your site after the fix
The quick scan is free for any public site and needs no signup. Checks that touch your database or files run only after you prove you own the site.
Choose a scan level →