Git format-patch: create email patches
git format-patch turns your commits into email-formatted patch files. The historical open source contribution workflow, still used for the Linux kernel.
What is git format-patch?
git format-patch converts commits into email-formatted .patch files. Each file contains the diff, commit message, author, and date.
It is like putting a commit in an envelope: you can send it by email, share it on a forum, or apply it to another repository with git am.
Git format-patch syntax
git format-patch -1Patch of the latest commit
git format-patch -3Patches of the last 3 commits
git format-patch main..featurePatches for an entire branch
Git format-patch in practice
Creating and applying patches.
Creating patches
Applying with git am
Essential format-patch commands
git format-patch -1Latest commit as patch
git format-patch -o dir/Save to a directory
git format-patch --stdoutOutput to terminal
git am file.patchApply an email patch
git am --abortAbort the current application
git send-email *.patchSend patches by email
Common mistakes with git format-patch
Applying with apply instead of am
Patches from format-patch contain metadata. Use git am (not apply) to preserve the author and commit message.
Forgetting the application order
Numbered patches (0001, 0002...) must be applied in order. Use git am *.patch which sorts them automatically.
Conflicts during application
If the code has diverged, resolve the conflicts then git am --continue. Or abort with git am --abort.
Part of the Git Advanced guide
GitQuest is created by Anaïs (nouvelle fenêtre), web developer and head of education, specializing in tech training and digital accessibility.
Questions about git format-patch
Contribute to open source with GitQuest
Learn open source contribution workflows with GitQuest investigations.
Start the investigations