📂
Security

Secrets in a public GitHub repo: what to check before you publish

03.12.2026
← All articles

Developers make repositories public for portfolios, open source contributions or simply free hosting. That is a good habit, but a public repository is a folder open to the whole world, and it exposes not just the current files but the entire history: every commit, every deleted file and every author's details. Many leaks start with files that were "deleted long ago".

What leaks besides keys

The most dangerous item is a database dump: a developer copies the production database for testing, drops it into db/ and commits it, complete with customer names, phone numbers, addresses and password hashes. Excel or CSV exports of orders or subscribers are another classic. Repositories also collect private SSH keys such as id_rsa or .pem files, configs with server IPs and secret admin paths, error logs, and "test" accounts that actually work in production. Individually they look minor; together they hand an attacker a map of your system: where the server is, which panel to try, which usernames exist and what the database looks like. Forks deserve a thought too, because a fork made while a repository was public keeps its own copy of the history.

Example: a school portal

A developer who built an online gradebook for a private school in Tashkent makes the repository public for a portfolio. The current files are clean, but a commit from a year ago still contains db/school_backup.sql with pupils' names, classes and parents' phone numbers, a few clicks away for anyone. A leak of children's data is a serious reputational and legal problem for everyone involved, and the developer never intended to publish any of it.

Audit before publishing

git ls-files | grep -iE '\.env|\.sql|\.csv|\.xlsx|id_rsa|\.pem|\.key|backup|dump'
git log --all --diff-filter=A --name-only --format="" | sort -u | grep -iE '\.sql|\.env|\.csv|\.pem|id_rsa'
git log --all -p | grep -inE 'password|passwd|secret|token|api_key' | head -50
git log --all --format='%an <%ae>' | sort -u

Run these on a full clone with all branches fetched, not on a shallow copy, otherwise old commits may simply be missing from the search. The first command checks tracked files, the second lists every file ever added on any branch, the third searches the full history for secret-like strings and the last shows which email addresses your commits expose. To hide your personal address, enable email privacy in GitHub settings and use the noreply address it gives you:

git config --global user.email "12345678+username@users.noreply.github.com"

Publishing without the old history

If problems turn up and the history is not essential, publish a fresh, history-free branch to a separate public repository:

git checkout --orphan public-main
git rm -r --cached db/ exports/
git commit -m "Public version"
git remote add public https://github.com/misol/school-portal.git
git push public public-main:main

The private repository keeps its history; the public one contains only a reviewed state. If history must be kept, strip the files with git filter-repo first. Any real key found in an already public repo must be revoked at the provider, because cleaning history cannot recall copies already taken.

.gitignore and the exposed .git folder

.env
.env.*
!.env.example
*.sql
*.sql.gz
*.csv
exports/
*.pem
*.key
id_rsa*
*.log

.gitignore only affects untracked files; already committed ones need git rm --cached. A related risk: a private repo deployed with git clone straight into the public web folder exposes .git, from which the whole repository can be reconstructed. Check with curl -I https://example.uz/.git/HEAD; a 200 means it is open. On sayt.uz hosting you can block it in .htaccess, and on a VPS location ~ /\.git { deny all; } in Nginx does the job.

Related articles

📄 XXE Vulnerabilities and XML Security: Stopping External Entities 🚨 Where to report a cyberattack in Uzbekistan 🧩 Subresource Integrity (SRI): protecting external scripts 🌐 What Is SSRF and How to Protect Your Server From It
🌐 Language
🇺🇿 O⁠'zbek 🇺🇿 Özbek (yangi) 🇺🇿 Ўзбек 🇷🇺 Русский 🇬🇧 English ✓