Skip to the note
zecrazytux.net development  |  note index

~ / development / git

development

Git notes on patches and branches

Development Git Patches

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:

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.