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

Click any option to expand

Beginner (1)

Add a Signed-off-by trailer with your name to each commit.

When neededProjects that require a sign-off chain

Example

git am -s 0001-fix.patch

Intermediate (1)

If a patch does not apply cleanly, fall back to a three-way merge (may leave conflicts).

RecommendedApply patches made on a slightly older base

Example

git am -3 0001-fix.patch

Choosing the Right Option

Applying patches

Files or commits?

CommandCreates a commit
git apply fix.patchNo — files only
git am fix.patchYes — with the original author

Examples

Apply patches

git am 0001-*.patch

Each file becomes a commit.


Add your sign-off

git am -s 0001-fix.patch

Append Signed-off-by with your name.


Stop a failed run

git am --abort

Back to how things were.

Workflow Examples

1
git switch -c review main

A branch to test them

2
git am ~/patches/*.patch

Apply 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.