Skip to main content

Sign in

Save your progress and access it from any device.

Or with email

Don't have an account?

Privacy policy

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.

Open source

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 -1

Patch of the latest commit

git format-patch -3

Patches of the last 3 commits

git format-patch main..feature

Patches 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 -1

Latest commit as patch

git format-patch -o dir/

Save to a directory

git format-patch --stdout

Output to terminal

git am file.patch

Apply an email patch

git am --abort

Abort the current application

git send-email *.patch

Send 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

A

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