git am
Patching & Rewriting
Apply patches from email files as commits
The 'git am' command (apply mailbox) takes patch files made by git format-patch and turns each one into a commit, keeping the original author, date and message. It is the receiving end of email-based contribution. If a patch no longer applies, git am stops; fix it and run git am --continue, or give up with git am --abort.
Synopsis
git am [--signoff] [--3way] [<mbox> | <patch-file>...]
git am (--continue | --skip | --abort)[ ] optional| or<arg> placeholder... repeatable--flag option
Options
Choosing the Right Option
Applying patches
Files or commits?
| Command | Creates a commit |
|---|---|
git apply fix.patch | No — files only |
git am fix.patch | Yes — with the original author |
Examples
Apply patches
git am 0001-*.patchEach file becomes a commit.
Add your sign-off
git am -s 0001-fix.patchAppend Signed-off-by with your name.
Stop a failed run
git am --abortBack to how things were.
Workflow Examples
1
git switch -c review mainA branch to test them
2
git am ~/patches/*.patchApply them
3
git log --oneline main..Check what arrived
Troubleshooting
error: patch failed … patch does not apply
Cause: Your files differ from the patch’s context
git am --abort, then retry with --3way, or ask for a rebased patch
Tips & Pitfalls
Best Practices
- ✓Apply patches on a fresh branch, not straight onto main.
Common Mistakes
- ✗Using git apply when you want commits — apply only changes files.
- ✗Leaving a failed git am half-done: finish with --continue or --abort.
FAQ
A:
It stands for "apply mailbox": it reads patches in email (mbox) format.