Advanced·12 min·engineering · git · devops
Git for Python devs
Git — the 20% you'll use 80% of the time
Mental model
- Working tree — files on disk.
- Staging area (index) — the shopping cart for your next commit.
- Commits — permanent snapshots.
- Branches — pointers to commits. Cheap. Make lots.
- Remote — a git repo somewhere else (GitHub).
The three-day-a-week loop
git switch -c feat/thing— new branch.- Code +
git add -p+git commit -m "...". Small commits. git push -u origin feat/thing— open a PR.- Merge, then
git switch main; git pull.
git add -p is the pro move
Stages hunks interactively — you can commit one logical change even if you've made three in the file. Pushes you toward small, reviewable commits.
Commit message style (Conventional Commits)
feat: add JWT authfix: handle empty user list in /usersrefactor: extract email senderdocs: update READMEtest: cover divide-by-zero
Makes changelogs writable by grep.
Rescue commands
git stashwhen someone needs your machine urgently.git reflogshows every HEAD move — you can recover deleted branches for ~90 days.git commit --amendfixes the last commit (message or content). Don't amend after pushing.git revert <sha>— safe undo that creates a new commit.
Try it
- Init a repo locally, make 3 commits, then
git log --graph. - Create a branch, change a file, merge back, delete the branch.