Git Cheat Sheet
Version control CLI for cloning repos, hunting exposed secrets in history, and recovering source during web assessments.
Overview
Git tracks source history. Misconfigured .git exposure lets attackers rebuild repositories and mine commits for credentials, API keys, and internal paths — common in web pentests and CTFs.
Authorized testing only. Use only on systems, networks, and accounts you own or have explicit written permission to test. Unauthorized access is illegal.
Install
sudo apt install -y gitgit --versionEssential commands
Clone
git clone https://github.com/org/repo.gitgit clone user@host:/path/repo.gitStatus / log
git statusgit log --oneline -20Show file at commit
git show HEAD:config.phpCommon workflows
Dump with git-dumper
pip install git-dumpergit-dumper https://target/.git/ ./loot/cd loot && git checkout .git log -p | grep -iE 'password|api_key|secret'Manual wget recovery (if dumper fails) —
wget -r -np -nH --cut-dirs=1 https://target/.git/git checkout -fSearch entire history for secrets —
git log -p | grep -i passwordgit secrets --scan # if installedtrufflehog git file://./repoAll commits touching file
git log --all --full-history -- env.productionRecover deleted file —
git log --diff-filter=D --summarygit checkout COMMIT_HASH^ -- path/to/deleted.phpBranches and stashes —
git branch -agit checkout developgit stash listgit stash show -p stash@{0}Submodule / config leaks —
cat .git/configgit submodule update --init --recursiveFlags reference
clone URL | Copy repository |
|---|---|
log -p | Patch per commit |
show REF:PATH | File at revision |
checkout BRANCH | Switch branch |
reset --hard ORIGIN | Discard local (careful) |
reflog | Recover lost commits |
grep -r pattern $(git rev-list --all) | Search all commits |
Tips
- .git/HEAD + objects/ exposure is enough for reconstruction — test / .git/HEAD (no space).
- Developers commit .env then delete — still in history; use git log -p -- .env.
- For GitHub/GitLab APIs use tokens with least privilege during authorized audits.
- After dump, run gitleaks / trufflehog on full tree.