git-am
Apply patches from a mailbox file
TLDR
Apply and commit changes following a local patch file
Apply and commit changes following a remote patch file
Abort the process of applying a patch file
Apply as much of a patch file as possible, saving failed hunks to reject files
SYNOPSIS
git am [options] [--] [mbox | Maildir]...
PARAMETERS
--3way
Fall back on 3-way merge if patch does not apply cleanly
--apply
Apply patches without committing (synonym: -3)
--binary
Read patches from binary stdin
--committer-date-is-author-date
Use patch author's date as committer date
--empty
Keep commits with no changes (does not apply to -3)
--ignore-date
Use current timestamp for author date
--ignore-space-change
Ignore changes in amount of whitespace (synonym: -w)
--ignore-whitespace
Ignore whitespace when finding context to apply patch
--interactive
Run interactively to let user choose hunks
--keep
Pass -k flag to git patch-id
--keep-cr
Do not remove \r from lines ending with CRLF
--keep-non-patch
Pass lines before/after patch through unchanged
--mbox
Pass --mbox to underlying git am (stdin only)
--merge
After failing, produce file to edit for merging (synonym: -m)
--no-verify
Bypass pre-commit and commit-msg hooks
--patch-border
Detect patch boundaries by @@@ lines
--quoted
Patches have quoted printable encapsulation
--reject
Like plain git apply, output rejected hunks separately
--resolv-msg=
Resolve commit message ambiguities using msg-id
--save-opts[=
Save options in .git/info/am_opts file
--scissors
Strip everything before line matching scissors line
--signoff
Add Signed-off-by trailer to commit message
--utf8
Pass --utf8 flag to git mailinfo
--whitespace=
Detect new or modified lines with specified whitespace errors
-C
Ensure
-p
Remove
-q
Be quiet
-u
Pass -u flag to underlying git mailinfo (discontinued)
--abort
Restore state before applying patches
--continue
Resume applying remaining patches after fixing conflicts
--quit
Abort but keep current index state and manually resolved hunks
--show-current-patch
Show the current patch being applied
DESCRIPTION
The git am command applies a series of patches from standard input or mailbox files (mbox format) to the current branch. It extracts commit metadata such as author name, email, date, and commit message, then uses git apply to patch the files and git commit to create new commits.
This is particularly useful for integrating changes from email discussions or mailing lists, preserving the original authorship and message history. If a patch fails to apply cleanly, git am pauses, allowing manual resolution of conflicts. Users can then continue with git am --continue, abort with git am --abort, or quit with git am --quit.
Options control application behavior, like using three-way merges for better conflict handling (--3way), ignoring whitespace differences, or trimming quoted text (--scissors). It supports interactive mode for selective hunks and can resolve message ambiguities (--resolv-msg). By default, it verifies commits unless --no-verify is used.
git am is safer than raw patch commands as it integrates fully with Git's history, but requires patches generated by git format-patch for best results.
CAVEATS
Requires patches in git-compatible format (e.g., from git format-patch); binary files need --binary; whitespace mismatches can cause failures without appropriate options; no support for directory rename detection; conflicts require manual intervention.
COMMON WORKFLOW
Generate patches with git format-patch, send via email, apply with git am --signoff.
For conflicts: edit files, git add, git am --continue.
STDIN USAGE
git am < /path/to/patches.mbox or git am --signoff to pipe from stdin.
HISTORY
Introduced in Git 1.0.0 (2005) as a core command for applying email patches. Evolved with options like --3way (Git 1.6.1, 2008) for better merges, --interactive (Git 1.7.8, 2010), and state management (--abort/--continue/--quit in Git 1.7.0, 2010). Remains essential for maintainer workflows with public-inbox mailing lists.
SEE ALSO
git-apply(1), git-format-patch(1), git-cherry-pick(1), git-rebase(1), git-mailinfo(1), patch(1)


