How to Use Git Format Patch

Just like python, I love using git. It’s versatile and does simplify a lot of developmental tasks.


With a distributed version control system like Git, we can actually send a path for someone to review without the need to have the centralized git repository using the git format-patch feature.


This is useful when the remote git repository is down or behind or behind an artificial throttling IT system.


Here are few ways to create patches

Creating patches from commits


let’s say you are in the “bug_fix“ branch and you want to have all the patches since master.

git format-patch master


This will create multiple patches per commit. We can create a single patch for multiple commits by using the –stdout option and directing the output to a file:

git format-patch master --stdout > mypatch.patch

One can also create a patch from git diff

git diff > something.patch

or from cache

git diff --cached > something.patch

How to use the patch?

Once you have received a patch how do you use it?


When you receive a patch file from someone, you can easily apply the patch using the git am command or git apply command.

git apply mypatch.patch


This command applies the patch but does not create a commit.

git am mypathc.patch

This command applies the patch and does create a commit with the original command

Hope this helps. It really helps me these days.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s