All Articles

Creating and applying a patch with Git

Here’s some commands to simply create a patch and apply a patch with Git. There’s a bunch of different ways to do it, but here are the helpful ones for me.

Create a patch with Git

General format

$ git format-patch <your-branch-name-here> <choose-your-options>

General usage to create patch from master

$ git format-patch master

You created a branch off master and you just need 1 whole, aggregated patch

$ git format-patch master --stdout > my-custom-patchname.patch

--std-out ➡️ Basically doesn’t create a patch for each commit > my-custom-patchname.patch ➡️ creates/outputs into that file that you name

Applying a patch with Git

git am <patch-file-name>

If you want to make sure you’ve applied the patch correctly, run a git log --oneline.