- Developers who already know basic commit and branch actions
- Readers who want to understand command boundaries and risk
Command Reference
git-apply Tutorial
Explains how to use git-apply to apply patch content to the working tree or index.
- 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-apply is used to apply patch content to the working tree or index.
When it is a good fit
- when you need to apply patch content to the working tree or index
- when you want this step to be repeatable instead of ad hoc
- when you need a clearer mental model of what Git is recording or updating
Basic example
git apply fix-login.patch
What to watch most closely
Patch-based workflows are sensitive to context drift, so confirm the base state and the recovery path first.
A safer working habit
Read the patch series first and keep abort, continue, or a backup branch ready.
Useful angles for understanding it
- Handle mailbox patches or patch files
- Exchange changes outside direct repository access
- Preserve commit boundaries instead of copying edits manually
Related reading
Read it alongside git status, git log, and git show so it is easier to see how the command changes history, refs, the index, or the working tree.
What problem this command solves in a workflow
git apply applies patch content to the working tree or index without creating commits. Unlike git am, it does not parse email headers or generate commit objects — it is purely a patch application tool for "how do I incorporate these changes into my working copy?"
Typical use cases
- Apply a diff or patch file to the working tree for review before deciding whether to commit:
git apply fix.patch. - Use
git apply --checkto verify a patch applies cleanly without actually modifying any files. - Apply patches to the index directly with
git apply --index, staging the changes without touching the working tree.
Diagram view
Special cases and boundaries
git applydoes not create commits — you must review, stage, and commit the changes yourself afterward.- Use
--checkto test whether a patch applies cleanly before actually modifying files, avoiding partial application. - If a patch was generated with different line endings or context lines, application may fail;
--ignore-whitespaceor--3waycan help. - Unlike
git am,git applydoes not preserve author information or commit messages from the original patch.