~ / development / git
developmentGit notes on patches and branches
Notes from moving changes between machines and projects without a shared server: a branch, a patch file and a clean history.
Work on a throwaway branch
Keep the main line clean and do experiments on their own branch.
git checkout -b work
# make changes and commit as usual
Turn commits into a patch
A patch is just the commits, exported as text. It can be mailed, copied on a stick, or reviewed by a colleague.
git format-patch main --stdout > change.patch
Park unfinished work
When something urgent arrives, set the current work aside, branch from the current line and carry the change over.
git stash save
git branch work
git checkout work
git stash pop
Apply a patch
Check first, then apply. Applying with the mail workflow keeps the author and message intact.
git apply --check change.patch
git am --signoff < change.patch
A branching flow that scales
Two long lived branches, one for released code and one for integration, plus short lived branches for features and fixes, keep releases predictable. The idea is well described in these references:
- A successful branching model
- The Git book is available free online; a link is collected on the resources page.
Scanned history for issue trackers
When an existing repository is connected to a project tracker, the tracker sometimes needs to read the whole history once before it stops missing old commits. That first pass can be slow, so it is best done deliberately rather than left to a background job.