Git & Repo
Hygiene

git log --graph --oneline --all

History rewriting, forensic archaeology, secret scanning, hook automation, and large-repo tooling. Beyond the daily commit cycle.

17 tools / commands
6 phases
Git 2.40+, GitHub Actions
Phase 17 tools shown
ToolPhaseKey commandsUse case
git rebase -i history
git rebase -i HEAD~5 git rebase -i --root git rebase -i origin/main # verbs: pick, squash, fixup, reword, drop, edit git rebase --abort git rebase --continue git reflog # recover from bad rebase: git reset --hard HEAD@{N}
Squash WIP commits before merge, reword messages, drop debug commits. --root rewrites the entire history: needed when changing the first commit. reflog is the safety net; every operation is recoverable for 90 days by default.
git filter-repo history
git filter-repo --path src/mymodule --invert-paths git filter-repo --path secrets.txt --invert-paths git filter-repo --path-rename old/path/:new/path/ git filter-repo --strip-blobs-bigger-than 10M git filter-repo --email-callback 'return email.replace(b"old@co.com", b"new@co.com")' git filter-repo --analyze
The correct tool for history rewriting: replaces git filter-branch which is 10 to 100× slower and has footguns. --analyze generates a report of large files and heavy committers before you operate. Always work on a fresh clone; it rewrites all refs.
git commit --fixup history
git commit --fixup=<sha> git commit --fixup=HEAD~2 git rebase -i --autosquash origin/main # set permanently: git config --global rebase.autoSquash true git config --global rebase.autoStash true
Create a fixup commit targeting a specific earlier commit, then --autosquash reorders and squashes automatically during rebase. Cleaner than manually reordering in the interactive editor. autoStash stashes dirty state before rebase and restores after.
git bisect forensics
git bisect start git bisect bad HEAD git bisect good v1.2.0 # git checks out midpoint; test, then: git bisect good # or: git bisect bad git bisect reset # fully automated: git bisect run pytest tests/test_regression.py
Binary search through history to find the exact commit that introduced a bug. bisect run is fully automated: pass any script that exits 0 for good, non-zero for bad. Finds the culprit in O(log n) checkouts regardless of history length.
git log (forensics) forensics
git log --graph --oneline --all --decorate git log -S "password" --all --oneline git log -G "def my_func" --all --patch git log --author="alice" --since="6 months ago" --stat git log --diff-filter=D --name-only --oneline git log --follow -p -- path/to/file
-S (pickaxe) finds commits that added or removed a string: useful for tracking when a secret was introduced. -G matches against the diff regex. --diff-filter=D lists only deleted files. --follow tracks renames.
git blame / annotate forensics
git blame -L 40,60 src/parser.go git blame -w -M -C src/parser.go git blame --ignore-rev <sha> src/parser.go git blame --ignore-revs-file .git-blame-ignore-revs src/parser.go # .git-blame-ignore-revs: list bulk-format/lint commits git config blame.ignoreRevsFile .git-blame-ignore-revs
-w ignores whitespace changes; -M detects moved lines; -C detects copied lines across files. --ignore-revs-file skips bulk formatter commits: commit .git-blame-ignore-revs to the repo so the whole team benefits.
git stash (advanced) forensics
git stash push -m "wip: refactor parser" -- src/parser.go git stash list git stash show -p stash@{2} git stash branch fix/parser stash@{0} git stash drop stash@{0} git stash clear
Partial stash with -- paths avoids stashing unrelated work. stash branch turns a stash into a proper branch: the right move when a stash grows into something real. show -p diffs the stash without applying it.
gitleaks security
gitleaks detect --source . -v gitleaks detect --source . --no-git gitleaks detect --source . --log-opts="HEAD~50..HEAD" gitleaks protect --staged gitleaks detect -f json -r report.json # .gitleaks.toml to allowlist false positives
Scans git history for secrets: API keys, tokens, private keys. protect --staged runs as a pre-commit hook. --log-opts scopes to a commit range for PR checks. Faster and more accurate than trufflehog on clean repos; lower false-positive rate.
trufflehog security
trufflehog git file://. --only-verified trufflehog git https://github.com/org/repo --only-verified trufflehog filesystem --path /path/to/dir trufflehog s3 --bucket my-bucket --only-verified trufflehog github --org myorg --only-verified
--only-verified actively validates found credentials against their respective APIs: dramatically cuts false positives. Scans beyond git: S3, GitHub org-wide, filesystems. Use for incident response or full-org audits; gitleaks for per-repo CI.
git-secrets security
git secrets --install git secrets --register-aws git secrets --add 'PRIVATE_KEY' git secrets --scan git secrets --scan-history git secrets --list
AWS Labs tool: installs as a git hook to block commits containing AWS keys or custom patterns. Lightweight and regex-based; simpler than gitleaks for teams that just need AWS credential protection. --register-aws covers all AWS key formats in one call.
pre-commit hooks
pre-commit install pre-commit install --hook-type commit-msg pre-commit run --all-files pre-commit run --from-ref origin/main --to-ref HEAD pre-commit autoupdate SKIP=ruff pre-commit run --all-files # .pre-commit-config.yaml pins hook versions by sha
Polyglot hook runner: one config drives ruff, gitleaks, hadolint, terraform fmt, mypy across languages. SKIP=hook-id bypasses a single hook without --no-verify. Pin hooks by SHA in .pre-commit-config.yaml for reproducibility; autoupdate bumps them.
commitlint hooks
echo "feat(api): add rate limiting" | commitlint commitlint --from=HEAD~5 commitlint --from=origin/main --to=HEAD # commitlint.config.js: # module.exports = { extends: ['@commitlint/config-conventional'] } # types: feat fix docs style refactor perf test chore ci
Enforces Conventional Commits format: prerequisite for automated changelogs and semantic versioning with tools like semantic-release or goreleaser. Run as commit-msg hook locally and in CI on PR title.
git sparse-checkout large repos
git clone --filter=blob:none --sparse <url> git sparse-checkout init --cone git sparse-checkout set src/myservice docs/ git sparse-checkout add infra/terraform/ git sparse-checkout list git sparse-checkout disable
Check out only specific directories from a monorepo without cloning the full tree. --filter=blob:none (partial clone) skips blob download at clone time: fetched lazily on access. Cone mode is faster than pattern mode for directory-based checkout.
git-lfs large repos
git lfs install git lfs track "*.parquet" "*.h5" "*.pkl" git lfs ls-files git lfs status git lfs migrate import --include="*.parquet" --everything git lfs fetch --all GIT_LFS_SKIP_SMUDGE=1 git clone <url>
Store large binaries (models, datasets, artifacts) outside the object store. migrate import retroactively moves existing blobs to LFS without rewriting commit SHAs. GIT_LFS_SKIP_SMUDGE=1 clones without downloading LFS objects: useful in CI that doesn't need them.
git maintenance large repos
git maintenance start git maintenance run --task=gc git maintenance run --task=commit-graph git maintenance run --task=prefetch git config --global core.commitGraph true git commit-graph write --reachable --changed-paths
Background maintenance for large repos: schedules GC, pack-file consolidation, and commit-graph updates. The commit-graph file dramatically speeds up git log --graph and git merge-base on deep histories. maintenance start registers a cron/launchd job automatically.
git worktree workflow
git worktree add ../hotfix origin/main git worktree add -b feature/new-api ../feature-work git worktree list git worktree remove ../hotfix git worktree prune
Check out multiple branches simultaneously in separate directories from a single repo: no stashing, no re-cloning. Switch to a hotfix while keeping a long-running feature branch open. Each worktree has its own index and working tree; they share the object store.
gh CLI workflow
gh pr create --fill --draft gh pr checkout <number> gh pr review --approve --body "LGTM" gh run list --workflow=ci.yml --limit=10 gh run watch <run-id> gh run rerun --failed <run-id> gh secret set MY_SECRET --body "$VALUE" --repo org/repo gh api repos/org/repo/actions/secrets | jq '.secrets[].name'
GitHub from the terminal: create PRs, watch CI runs, rerun failed jobs, manage secrets. --fill populates PR title and body from commit messages. gh run watch tails a live run without opening a browser. gh api hits any GitHub API endpoint with auth already configured.
git notes workflow
git notes add -m "reviewed by: alice" HEAD git notes show HEAD git log --show-notes=* git push origin refs/notes/* git fetch origin refs/notes/*:refs/notes/* # notes don't change commit SHA: safe post-push annotation
Attach metadata to commits without altering their SHA: CI test results, code review outcomes, deployment records, benchmark results. Notes are stored in a separate ref (refs/notes/) and must be pushed/fetched explicitly. Underused for audit trails.
No tools match this filter.