git am
This command is useful for taking patches that were sent or exported via email and turning them into real commits in your current branch while preserving metadata like author, date, and commit message.
This command reads one or more patch files (often in mbox format) from files or standard input and applies them as new commits on top of the current HEAD, using the patch content to change files and the email headers to populate the commit metadata. By default, it expects input like git am < 0001-some-change.patch or git am patches.mbox, and for each email-style patch found, it applies the diff, sets the commit author from the From: header, uses the email subject as the commit message, and commits the result. Commonly paired flags include -3 (same as --3way) to fall back to a three-way merge when a patch does not apply cleanly, --signoff to append a Signed-off-by: line to the commit message, --keep-cr to preserve carriage returns in the patch, and --whitespace=<fix|nowarn|warn|error> to control how whitespace issues are handled during application. Other useful options are --continue, --skip, and --abort, which you run as separate commands (e.g., git am --continue) to manage an in-progress patch application when conflicts occur.
Beyond the basic usage, this command can be combined with git format-patch to move commits between repositories without using a shared remote: one side exports commits with git format-patch, producing .patch or .mbox files, and the other side replays them with this command. If a patch fails to apply cleanly, you typically resolve conflicts manually, stage the resolved files, and then run git am --continue to proceed; if a particular patch is not desired, you can git am --skip it, and if the whole operation should be canceled, git am --abort restores the repository to its pre-apply state. For workflows that prefer direct commits from a remote branch instead of email patches, git cherry-pick is a closely related alternative that replays commits directly from another branch, while git apply is a lower-level tool that applies patch hunks to the working tree without creating commits, which you then commit manually.
Examples:
git am < 0001-fix-typo.patchgit am --3way --signoff patches.mbox