BreachHunter
Pricing Blog Log inSign up
● thermal huntscan engines onlineassessment only — no exploits
  1. Home
  2. Blog
  3. Exposed .git Directory: What It Leaks and How to Check

Guides · ← All guides

Exposed .git Directory: What It Leaks and How to Check

Last updated: October 31, 2026 · Reviewed October 2026 · 7 min read

By the Ingenious AI team

The short answer: If your /.git folder is reachable over the web, anyone can download it piece by piece and rebuild your entire source tree — including secrets that were committed and later "deleted", which git history never forgets. BreachHunter checks /.git/HEAD, /.git/config and /.git/logs/HEAD on every scan and rates an exposed .git CRITICAL. Checks as shipped, October 31, 2026.

Of the 33 sensitive paths BreachHunter probes — the full module list is here — the exposed .git directory is the one that turns a minor misconfiguration into a full compromise. It happens innocently: a site gets deployed by copying a working folder to the server, and the hidden .git folder rides along. The site works fine. So does the download of your entire codebase, for anyone who asks.

How does a .git directory end up in your web root?

Git stores everything about a repository — every file version, every commit, every branch — in the .git folder at the project root. Deploy by dragging the project folder onto a server, syncing it with a tool that includes hidden files, or cloning the repo directly into the web root, and that folder ships with it. Web servers happily serve it: nothing in a default configuration tells them not to. The site owner sees a working site. A scanner sees an open archive.

What exactly leaks when .git is exposed?

File an attacker requestsWhat it gives themBreachHunter severity
/.git/HEADConfirmation the repository is exposed, and the current branch pointer — the starting thread for full reconstructionCRITICAL
/.git/configYour repository's remote URLs — which can embed live credentials (tokens inside https URLs) — and your repo host and project nameCRITICAL
/.git/logs/HEADThe reflog: commit history, branch names, and the map of objects to download nextHIGH
The objects themselvesEvery committed file at every committed version — source code, configuration, and secrets that were later removed—

Source: SENSITIVE_PATHS table, BreachHunter engine (app/pentest.py), read October 31, 2026. The last row is the one that matters: the first three files are just the index. The objects they point to are the library.

How do attackers rebuild the tree?

Slowly and mechanically — which is why it scales. Starting from /.git/HEAD and the reflog, a tool requests the commit objects, then the tree objects those commits name, then every blob in every tree. Git objects are stored compressed, but they are not encrypted, and the paths are predictable hashes. Open-source tools automate the whole walk. The attacker ends with your repository exactly as your team has it — same history, same deleted files, same key you committed in March and removed in April. Deletion is not erasure in git; it is just the newest commit. Our companion investigation covers the archive side of the same problem: deleted files the web archive keeps serving.

How do you check your own site in 30 seconds?

Ask your server for the file, the way a stranger would:

curl -I https://your-site.com/.git/HEAD

A response of 200 with a body like ref: refs/heads/main means the repository is public — treat it as urgent. A 403 or 404 means your server is already blocking it. Then run the free BreachHunter scan, which checks all three git paths plus the other 30 sensitive files in about a minute, so you are not relying on one manual probe.

How do you fix an exposed .git directory?

Three steps, in this order. First, block it at the server layer today. On nginx:

location ~ /\.git { deny all; }

On Apache:

RedirectMatch 404 /\.git

Second, remove it from the deploy. Ship a build artifact — an archive of the built site — instead of the working folder, so no .git exists on the server to protect. Third, rotate. Every secret that ever entered the repository's history — database passwords, API keys, tokens in remote URLs — must be revoked and reissued. Closing the door does not un-copy what may already have been downloaded. If you are working through a full scan report, our triage guide explains where this finding sits in the fix order (spoiler: first).

Check your site for an exposed .git — free scan →

Frequently asked questions

How do I check if my .git directory is exposed?

Request https://your-site.com/.git/HEAD in a browser or with curl. If you see a line like 'ref: refs/heads/main', your repository metadata is public. A 403 or 404 means the server is blocking it, which is what you want. BreachHunter checks /.git/HEAD, /.git/config and /.git/logs/HEAD automatically on every scan.

If I delete a secret from my code, is it gone?

No. Git keeps every committed version. A key removed in a later commit is still readable in the earlier one, and an exposed .git directory hands an attacker the whole history. The only safe response to a leaked secret is rotation: revoke the old key and issue a new one.

Does an exposed .git directory mean I have been hacked?

Not necessarily — it means the door has been open, not that anyone walked through it. Treat it as urgent anyway: automated scanners probe for /.git constantly, and you cannot prove a negative from your own logs. Close it, then rotate any secret that ever touched the repository.

What is the fastest safe fix?

Deny web access to /.git at the server layer (one rule in nginx or Apache), verify the path now returns 403/404, and redeploy from a build artifact that does not contain the .git folder at all. Then rotate the secrets in the repository's history.

After the fix: assume the history is already public

Blocking the directory stops new downloads. It does nothing about the copy someone may already have, and a .git directory that sat exposed for months should be treated as published source code — including every secret that ever appeared in any commit, even ones later 'removed'. Deleting a secret from the current code does not delete it from history; the old commit still carries it.

So the response order matters: rotate every credential that appears anywhere in the repository's history first, then block access, then check your server logs for requests to /.git/ paths to learn whether anyone actually took the copy. Rotation is the step teams skip because blocking feels finished. It is not — blocking closes the window, rotation changes the locks.

Sources

The authorities this guide is built on, in the form we check our own work against:

  • OWASP Web Security Testing Guide (2021) — fingerprinting and configuration test cases for exposed repositories.
  • Git documentation (2025) — what the .git directory contains and why it rebuilds the whole tree.
Share this: X · Facebook · LinkedIn · WhatsApp

Related guides

  • Website Security Test: What It Checks, What It Misses, and How to Read Yours · 9 min read
  • Website Security Cheat Sheet: Headers, TLS, Cookies and Exposed Files · 7 min read
  • What a Website Security Assessment Actually Tests · 10 min read
  • TLS/SSL Basics: What Your Certificate Says About Your Site · 8 min read
  • Common Website Misconfigurations (and How to Fix Them) · 11 min read
  • Reading Your First Pentest Report: From Score to Action · 9 min read
  • Deleted ≠ Gone: What the Wayback Machine Keeps After You Delete Your Secrets · 9 min read
  • SQL Injection in Plain English: How One Login Box Can Read Your Database · 9 min read
  • What Does a Website Security Scan Check? · 8 min read
  • Security Headers Missing? What Each Header Stops · 7 min read
  • How Much Does a Penetration Test Cost in 2026? · 7 min read
  • Website Security Checklist for Small Teams (60-second self-check) · 6 min read
  • Reading Your Scan Results: Which Findings Fix First? · 7 min read
  • Content-Security-Policy Missing: What CSP Does and How to Add It Safely · 8 min read
  • HSTS Missing: What Strict-Transport-Security Prevents · 7 min read
  • Clickjacking and X-Frame-Options: How Framing Attacks Work · 7 min read
  • Cookie Flags Explained: Secure, HttpOnly and SameSite · 8 min read
  • Exposed .env File: What Leaks, What Attackers Do Next, What You Do First · 8 min read
  • Directory Listing Enabled: What It Shows Attackers and How to Disable It · 7 min read
  • Mixed Content: Why Your HTTPS Page Still Loads Insecure Resources · 7 min read
  • Expired SSL Certificate: What Breaks, Why Renewal Fails, and How to Catch It Early · 7 min read
  • TLS 1.0 and 1.1 Still Enabled: Why Old Protocols Show Up as a Finding · 7 min read
  • Open Ports on a Web Server: Which Ones Should Never Face the Internet · 8 min read
  • No SPF or DMARC Record: How Missing Email Auth Exposes Your Website · 7 min read
  • Subdomain Takeover: How a Dangling DNS Record Lets Attackers Claim Your Name · 7 min read
  • Forgotten Subdomains: The Staging Site You Forgot Is Still Public · 7 min read
  • WordPress Security Scan: The Exposures an Assessment Finds on WordPress Sites · 8 min read
  • Exposed Backup Files: .bak, .old and .zip Files Sitting in Your Web Root · 7 min read
  • phpinfo() in Production: The Diagnostic Page That Maps Your Server for Attackers · 7 min read
  • Server Version Banners: Why Your Headers Point Attackers to the Right Exploit · 7 min read
  • End-of-Life Software: Running a Server Stack Nobody Patches Anymore · 7 min read
  • CORS Misconfiguration: When Cross-Origin Sharing Opens Your Data to Any Site · 7 min read
  • Open Redirect Vulnerability: How Your Own Domain Sends Visitors to a Phishing Page · 7 min read
  • Dangerous HTTP Methods: What TRACE, PUT and DELETE Should Never Answer · 7 min read
  • Host Header Injection: Poisoned Reset Links and Cache Attacks Explained · 7 min read
  • What Is security.txt? The Small File That Lets Researchers Reach You · 6 min read
  • Admin Panel Exposed to the Internet: What an Assessment Flags and Why · 7 min read
  • phpMyAdmin Exposed: Why This Database Door Is a Prime Brute-Force Target · 7 min read
  • Spring Boot Actuator Exposed: Environment Dumps, Heap Leaks and Shutdown Endpoints · 7 min read
  • Debug Console in Production: The Finding That Can Become Code Execution · 7 min read
  • Exposed AWS Credentials File: The /.aws/credentials Finding, Explained · 7 min read
  • Referrer-Policy and Permissions-Policy: The Two Quiet Headers You Are Probably Missing · 6 min read
  • Exposed package.json: Your Dependency List Is a Recon Gift · 6 min read
  • DNS Zone Transfer Open (AXFR): Handing Out Your Entire DNS Map · 6 min read
  • Certificate Name Mismatch: Why the Cert Does Not Match Your Domain · 6 min read
  • Website Security Assessments for Agencies: Checking Every Client Site Without a Security Team · 8 min read
  • SaaS Security Questionnaires: What Buyers Check About Your Website First · 8 min read
  • Ecommerce Website Security: The Exposures That Put Your Checkout at Risk · 8 min read
  • Small Business Website Security: The Checks That Matter at Your Size · 7 min read
  • How to Prepare for a Website Security Assessment (and Read the Report Calmly) · 7 min read
  • Vulnerability Severity Explained: What Critical, High, Medium and Low Actually Mean · 7 min read
  • Retest After Fixes: How to Prove a Security Finding Is Actually Closed · 7 min read
  • Security Assessment vs Vulnerability Scan vs Pentest: What Is the Difference? · 7 min read
  • How Long Does a Website Security Scan Take? · 6 min read
  • Website Security Drift: Why Last Month's Clean Scan Is Already Out of Date · 7 min read
  • WordPress Site Keeps Getting Hacked After Cleanup · 8 min read
  • Google Blacklist Removal: Getting the Red Warning Off Your Site · 8 min read
  • VirusTotal Flagged My Site: How to Clear a False Positive · 8 min read

Related from the Ingenious AI suite

  • Ingenious AI — the full suite of security and compliance tools
  • DomainGuard — domain impersonation and typosquat defense
  • See BreachHunter pricing →
BreachHunter · by Ingenious AI · read-only security assessment — scan only targets you own or are authorized to test
About · Contact · Blog · vs Intruder · Privacy · Terms · Security · Threats · Nextcloud Check · Verify Evidence · Help · Redeem
More from Ingenious AI:
DisclosureGuard — AI disclosure compliance · Vibe-Code Audit — AI code security scanner · Rogue-Agent Defense — AI agent firewall · ChatBreaker — AI chatbot red-teaming · ModelMinder — AI model deprecation radar · TermsWatch — AI vendor terms monitor · Agent Flight Recorder — tamper-evident agent audit trails · Agent Auth Gateway — agent credentials & kill switch · DomainGuard — domain impersonation defense · Agent Passport — Know-Your-Agent registry · AgentGate — agent policy publisher · AgentBlock — AI agent & crawler access control · BoundaryVault — agent log forensics · Agentic Receipts — verifiable agent payment receipts · EvalEgress — eval-to-production exposure scan · HomeShield MCP — home AI server exposure check · WireWatch — payment verification ceremony · ADMT Notice Kit — AI decision notice compliance · DueLadder — human-approved invoice chasing · Agent-Ready Store Audit — can AI agents buy from your store · ContentCraft AI — content operations · AgentReady — agent-readiness checks · AI Audit Exchange — AI audit exchange · CallbackShield — callback & webhook protection · CompanionGuard — AI companion safety guardrails · CRAClock — EU Cyber Resilience Act deadline clock · EInvoice Translator — e-invoice format translator · GEOFixer — geo & local listing fixes · MandateGuard — agent spending mandates · OutcomeMeter — AI outcome measurement · ProvenanceGuard — content provenance checks · ReviewDesk — review response desk · ReviewProof — verified review evidence · TakedownCoop — coordinated phishing takedowns · TrustGate — trust & safety gating · BreachHunter — website penetration testing · All 36 platforms — the Ingenious AI portfolio

We use cookies. Necessary cookies keep the site working. With your permission we also use analytics cookies (to understand usage) and marketing cookies (for ads). Read our privacy policy.

NecessaryRequired for login, security and core features. Always on.
AnalyticsHelps us understand which pages are useful.
MarketingUsed for advertising and measuring ad performance.

    No match. Try “pricing”, “php2shell” or “contact” — or press Esc to close.

    ↑↓ navigate · Enter open · Esc close