Skip to content
Latchkey

git format-patch: Usage, Options & Common CI Errors

git format-patch exports commits as .patch files (one per commit) ready to email or replay with git am.

format-patch is half of the email-patch workflow. It produces mbox-formatted patches that git am consumes.

What it does

git format-patch creates one mailbox-format patch file per commit in a range, preserving author, message, and diff so the series can be reviewed or reapplied.

Common usage

Terminal
git format-patch -1 HEAD           # the last commit
git format-patch main..feature     # a range
git format-patch -3 --stdout > series.mbox
git format-patch origin/main --cover-letter

Options

FlagWhat it does
-<n> / -NLast n commits
--stdoutWrite the series to stdout
--cover-letterAdd a summary cover letter
-o <dir>Output directory for patch files
<since>..<until>Commit range to export

Common errors in CI

An empty or wrong range produces no patches silently. fatal: ambiguous argument means the base ref is missing (often a shallow clone) - fetch the base branch first, or use an explicit -<n> count instead of a symbolic range.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →