Exposed .git Directory: How Your Source Code Leaks and How to Stop It

A public .git folder lets attackers download your website's full source code and history, including old secrets. How to check and fix it.

Yrzo AI28 November 2026 2 min read

The problem in one sentence

If your website deploys by copying a git repository onto the server and the .git folder is reachable over the web, anyone can download your entire source code and its full history.

Why it is worse than it sounds

The .git folder contains every version of every file ever committed. That often includes:

  • API keys or passwords that were committed once and "removed" later
  • old configuration files and database credentials
  • admin routes and hidden endpoints
  • the exact code, which makes finding other vulnerabilities far easier

Freely available tools can rebuild a full repository from an exposed .git folder in minutes, even when directory listing is switched off.

How to check your site

Try these in a private browser window:

  • https://yourdomain/.git/config
  • https://yourdomain/.git/HEAD

If either returns text (rather than 403 or 404), your repository is exposed. A free scan checks this automatically, along with exposed .env files and backups.

Is your site exposed to this?

Run a free, non-intrusive check of what attackers can see from outside. No account needed.

How to fix it

  1. Block dotfiles at the web server. Deny every path starting with /. except /.well-known/, which is needed for certificates and security.txt.
  2. Deploy build output, not the repository. Use a CI pipeline or deploy tool that copies only the files the site needs.
  3. Delete the folder from the server if it is not needed there.

If it was exposed

Treat it as a leak of everything in the history.

  • rotate every secret that has ever been committed, even if later deleted
  • review the code for vulnerabilities an attacker now knows about
  • check server and application logs for unusual access
  • in future, use a secret scanner in CI to stop secrets being committed at all

Our API key security guide covers rotation and storage.

  • /.svn/ and /.hg/ for older version-control systems
  • .DS_Store files that reveal folder contents
  • backup.zip, site.tar.gz and .sql dumps in public folders
  • directory listing switched on — see directory traversal

Make it part of every scan

Exposure checks take seconds and catch some of the most damaging mistakes. Yrzo AI includes them in every report — see plans.

Related reading: Exposed .env Files: Why They Are Dangerous and How to Check Yours · What Is Attack Surface Management? A Plain-English Guide · security.txt Explained: How to Add One to Your Website

exposed .git directorygit folder publicly accessiblesource code disclosure git.git security risk
Share

Check your own website in 60 seconds

Free check, no account needed. Want the full picture? Full reports start at £149, with up to 110 checks with a 14-day money-back guarantee.

Keep reading