- Developers who already know basic commit and branch actions
- Readers who want to understand command boundaries and risk
Command Reference
git-am Tutorial
Apply mailbox patch series as real commits, preserving author/message metadata in patch-by-email workflows.
- A basic mental model of worktree, index, and commits
- Comfort reading `git status` and a small commit graph
- Using local cleanup commands on already shared history
- Continuing to rewrite before confirming a recovery path
The short version
git am applies email-style patches and records them as commits, not just working-tree edits.
Best-fit scenarios
- ingesting mailing-list patch series
- preserving original author/subject metadata
- importing changes in non-platform collaboration models
Core flow
git am 0001-fix.patch
# or
git am *.patch
If conflicts happen:
git am --continue
git am --skip
git am --abort
Why it differs from git apply
git apply: apply file diffs onlygit am: apply diffs and create commits with mail metadata
Safer usage pattern
- run on a temporary branch first
- verify base alignment before apply
- avoid repeated blind
--skip; keep recovery checkpoints
Patch-series context drift can produce cascading conflicts. Syncing base first is often the cheapest prevention step.
Common mistakes
Mistake 1: expecting every patch to apply automatically
Context divergence still requires human conflict resolution.
Mistake 2: aborting immediately and losing useful progress
git am applies mailbox-format patches onto the current branch and creates new commits, preserving the original author information and commit metadata. Think of it as the step where "patches formally enter local history from an external source."
Evaluate already-applied commits before discarding series state.
Mistake 3: skipping patches without traceability
- Apply a series of patches received from external contributors or mailing lists directly onto your local branch.
- In a patch-based workflow, use
git amto convert received .patch files into proper commit records. - When you need to preserve the committer identity and full commit message, use
git amrather than manually copying changes.
Later it becomes hard to explain sequence gaps.
Special cases and boundaries
- When patch application fails,
git am --abortrolls back to the pre-application state without leaving half-finished commits. - Before running
git am, confirm a clean working tree withgit statusand preview the current patch with--show-current-patch. - If a patch's context does not match the current codebase, application will fail — first verify which version the patch was generated against.
- Email encoding, signature lines, and whitespace formatting can all affect patch parsing; use
--ignore-whitespaceor--3wayfor more tolerance when needed.
Good follow-up reads
git-format-patchgit-send-emailrecover after wrong cherry-pick