Git Configuration
Aliases, hooks, and sensible Git defaults for Python teams using uv, ruff, and pytest locally and in CI.
Search across all documentation pages
Aliases, hooks, and sensible Git defaults for Python teams using uv, ruff, and pytest locally and in CI.
git config --global user.name "Ada Lovelace"
git config --global user.email "ada@acme.com"
git config --global pull.rebase true
git config --global fetch.prune true
git config --global alias.lg "log --oneline --graph -20"When to reach for this:
# ~/.gitconfig (excerpt)
[user]
name = Ada Lovelace
email = ada@acme.com
[pull]
rebase = true
[fetch]
prune = true
[init]
defaultBranch = main
[alias]
st = status -sb
sync = "!git fetch origin && git rebase origin/main"
cleanup = "!git branch --merged main | grep -v main | xargs git branch -d"# .pre-commit-config.yaml (repo)
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.0
hooks:
- id: ruff
- id: ruff-format
- repo: local
hooks:
- id: pytest-quick
name: pytest quick
entry: uv run pytest -q tests/unit
language: system
pass_filenames: falseWhat this demonstrates:
defaultBranch = main for new repos.git/hooks/ or managed by pre-commit framework..gitattributes for nbstripout, LFS, linguist-generated.gpg.format ssh) on modern Git.| Setting | Value | Why |
|---|---|---|
pull.rebase | true | Linear feature integration |
fetch.prune | true | Remove stale remote branches |
rebase.autoStash | true | Rebase with dirty tree (careful) |
core.autocrlf | input on mac/linux | Avoid CRLF noise in Python |
init.defaultBranch | main | Consistent primary branch name |
# Repo-local identity for work laptop
git config user.email "ada@acme.com"
# Ensure hooks run
uv run pre-commit install
uv run pre-commit run --all-filesgit stash list hygiene.git config user.email per repo for contractors.--no-verify - Bypasses ruff on emergency commit. Fix: allow only break-glass; fix before merge..gitattributes * text=auto eol=lf.git commit -S -m "test" on one branch first.| Alternative | Use When | Don't Use When |
|---|---|---|
| Husky (Node teams) | Monorepo with JS + Python | Pure Python - pre-commit is native fit |
| CI-only gates | Hooks politically blocked | Developers push failing ruff often |
git config --global includeIf | Work vs personal repos on one laptop | Single employer machine |
| Manual checklist | Tiny team | Scale beyond ~5 developers |
Repo .pre-commit-config.yaml committed - everyone shares hooks; pre-commit install per clone.
git config gpg.format ssh and user.signingkey to public key path - GitHub verifies SSH signatures.
gh pr view --web or alias pr = "!gh pr view --web" after push.
Osxkeychain stores HTTPS tokens; prefer SSH for git operations.
Link from Environment Setup Checklist with copy-paste block.
~/.gitignore_global for .DS_Store, IDE files - supplements repo .gitignore.
.git-blame-ignore-revs for mass format commits - cleaner archaeology.
Rare in Python services - if used, submodule.recurse for clone/pull behavior.
feature.manyFiles true and partial clone git clone --filter=blob:none for huge monorepos.
git config pull.rebase false local override when merging release branches frequently.
Stack versions: This page was written for Python 3.14.0 (stable 3.14, maintenance 3.13), FastAPI 0.115+, Django 5.2, Flask 3.1, Pydantic 2, PyTorch 2.6+, pandas 2.2+, Polars 1.x, ruff 0.9+, and uv 0.6+.
Reviewed by Chris St. John·Last updated Jul 16, 2026