Synopsis
git am [--3way] [--abort] [--continue] [--skip] <mbox>...
Description
The git am command applies patches from a mailbox file — the kind produced by git format-patch or generated by emailing a diff. Unlike git apply, which only applies the diff content, git am recreates each patch as a commit, preserving the author, date, message, and other metadata embedded in the email.
This is the foundation of the email-based contribution workflow used by the Linux kernel and other projects: maintainers receive patches via email, save them to a mailbox, and apply them with git am. The result is exactly the same series of commits the author created.
In day-to-day use, git am integrates closely with shell aliases, editor plugins, and continuous integration. Power users often add aliases that combine flags they always pass, or wrap the command in scripts that enforce team conventions. Output formatting can be customized via Git config — pretty formats, color schemes, and pager behavior are all tunable. When something goes wrong, the first diagnostic step is usually to re-run the command with GIT_TRACE=1 in the environment, which reveals the underlying plumbing calls. For unusual situations, the --help output (git am --help) opens the full manual page with details on every option, including those rarely used in casual workflows but essential for debugging or scripting at scale.
Understanding how git am interacts with the rest of Git's data model — the object database, the index, refs, and the working tree — pays dividends. Each command operates on some subset of these pieces, and knowing which it touches helps predict outcomes and recover from mistakes. Reading the official Git documentation alongside hands-on practice in a throwaway repository is the fastest way to internalize the nuances. Most production issues with Git stem from one of three causes: surprising default behavior, partial network operations, or rewriting history that was already shared. A working mental model of git am's side effects helps avoid all three.
Common Options
| Option | Description |
|---|---|
--3way | Fall back to three-way merge if patch doesn't apply cleanly. |
--abort | Cancel an in-progress am. |
--continue / --resolved | Continue after fixing conflicts. |
--skip | Skip the current patch. |
-s, --signoff | Add Signed-off-by trailer. |
-k | Pass -k to mailinfo (keep subject). |
--whitespace=<action> | Handle whitespace errors. |
Examples
git am patches/*.patch
# Apply a series of format-patch outputs
git am --3way --signoff incoming.mbox
# Three-way merge fallback, add sign-off lines
git am --abort
# Cancel after a hopeless conflict
curl -L https://lore.kernel.org/.../t.mbox.gz | gunzip | git am --3way
# Apply patches downloaded from a public list
Common Mistakes
Forgetting --3way when patches were generated against a slightly different base often causes failures that --3way would handle. After resolving a conflict, run git am --continue, NOT git commit. Plain commit creates a malformed state.
Related Commands
git apply, git format-patch, git send-email, git mailinfo