Essential Git Commands
The daily-driver Git command set for Python teams - clone to commit to push, plus the inspection commands that make debugging history fast.
Search across all documentation pages
The daily-driver Git command set for Python teams - clone to commit to push, plus the inspection commands that make debugging history fast.
git status -sb
git diff
git add pyproject.toml uv.lock src/
git commit -m "feat(billing): add tax line item [BILL-42]"
git push -u origin feat/bill-42-taxWhen to reach for this:
main# Clone and configure identity (once per machine)
git clone git@github.com:acme/billing-api.git
cd billing-api
git config user.name "Ada Lovelace"
git config user.email "ada@acme.com"
# Daily loop
git checkout main
git pull --rebase origin main
git checkout -b feat/bill-42-tax
# ... edit Python files ...
uv lock # if dependencies changed
git add pyproject.toml uv.lock src/billing/tax.py tests/test_tax.py
git commit -m "feat(billing): add tax line item [BILL-42]"
git fetch origin
git rebase origin/main
git push -u origin feat/bill-42-taxWhat this demonstrates:
status -sb for branch and staged summarygit add stages snapshots to index.origin typically GitHub/GitLab; fetch downloads refs without merging.HEAD is current checkout.| Task | Command |
|---|---|
| What changed? | git status, git diff, git diff --staged |
| History | git log --oneline -20, git log -p file.py |
| Undo staging | git restore --staged file.py |
| Discard edits | git restore file.py |
| Stash WIP | git stash push -m "wip tax" |
| Update branch | git pull --rebase origin main |
# See who last touched a failing test
git blame tests/test_tax.py
# Find commit that changed default VAT rate
git log -S "DEFAULT_VAT" --oneline -- src/git add . catches secrets - .env slips into commits. Fix: .gitignore + git add -p for sensitive repos.uv sync --frozen fails. Fix: always uv lock with pyproject.toml edits.pull --rebase on private branches.--force-with-lease only on your feat/* before review..venv/ or __pycache__/. Fix: global gitignore for Python artifacts.git commit --amend or squash before PR.| Alternative | Use When | Don't Use When |
|---|---|---|
| GitHub Desktop / GitKraken | Visual diff preference | Scripting and server SSH workflows |
jj (Jujutsu) | Experimenting with VCS | Team standard is Git CLI |
| IDE git panel | Quick staging | Learning rebase conflict resolution |
gh pr create | PR from terminal | You need GitHub CLI installed |
Rebase onto main for clean PR history on private branches; merge on shared release branches per team policy.
git reset --soft HEAD~1 moves HEAD back one commit keeping staged files.
Imperative subject, ticket id, body explaining why - reference Conventions & Style Guide.
Yes when team uses pyenv/mise - documents interpreter pin alongside requires-python.
git branch -r after git fetch --prune removes stale remote-tracking branches.
git reflog then git checkout -b feat/x <sha> within default 90-day window.
git diff origin/main...HEAD shows PR delta three-dot style.
git tag -a v1.2.0 -m "release 1.2.0" then git push origin v1.2.0 when tag triggers deploy.
git clone --recurse-submodules for repos vendoring native deps - rare in pure Python services.
Configure SSH or GPG signing when org policy requires - git log --show-signature verifies.
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