Git & GitHub Practices
How to use version control effectively with AI agents. Branching, commits, pre-commit hooks, CI/CD, and automation patterns that prevent mistakes.
# commit_discipline
# Good
fix: timezone conversion dropping DST offset in March
feat: add Gmail noise filtering for newsletters
# Bad
fixed stuff
update
wip One feature or fix per commit. Don't bundle unrelated changes.
Commit after every working change. Don't accumulate.
Never git add . — add specific files to avoid secrets or binaries.
Check size first — git diff --cached --stat. No files over 1MB.
# branching_and_prs
Never edit main directly. Main auto-deploys on many projects. Direct edits = untested code in production.
git checkout main && git pull
git checkout -b fix/descriptive-name
# make changes, commit
git push -u origin fix/descriptive-name
# Create PR
gh pr create --title "Fix: descriptive name" --body "What and why"
# After CI passes → merge
# For public repos → squash merge
Branch prefixes: fix/, feature/, refactor/, docs/.
One feature per PR. Clear title + description. No secrets in diff.
# pre_commit_hooks
Automated checks that run before every commit. Catch bugs before they enter the repo.
Undefined Python names (ruff F821) — catches NameError before runtime
Checks staged content only (not working tree) — validates exactly what's being committed
Architecture: One shared hook file, all repos delegate to it. Change the rules once, every repo picks it up instantly.
# ci_cd
GitHub Actions run on every push and PR. Only check for real bugs — never style issues.
# gitignore
Any file with credentials must be gitignored. Provide a .example template instead.
# Always ignore
config.json # Secrets, API keys
*.db # SQLite databases
venv/ # Virtual environments
__pycache__/ # Python cache
node_modules/ # Node dependencies
.wrangler/ # Cloudflare cache
# Always provide
config.json.example # Template with placeholder values # automation
Git events trigger automated workflows — no manual intervention needed.
Push to main → webhook fires → VPS auto-pulls the repo
After pull, run sync scripts — update docs, refresh caches
Before commit, validate code — catch undefined names
On push/PR, run tests — gate broken code from merging
# lessons_learned
git diff --cached --stat first.