Development/Tutorials/Git/Create a patch

This page is mostly useful for people who want to submit a patch against a git repository, but for any reason don't want to use merge requests.

Setting up git

You can skip this part if your git is already set up correctly with your name and email address.

You will need to set up git for your user if you still did not do it. It's quite easy and it boils down to these two commands:

git config --global "Your name"
git config --global "Your email address"

Then you're good to go, and all your commits will be signed with your name and email

Using git-format-patch to send patches through email

This method will let you create a patch (or a set of patches) ready to be applied. We will suppose we want to add a FooClass to Amarok (which obviously does not exist).

Starting off

First of all, you will have to clone the repository. Amarok repository lies here: . Let's start by cloning the repository. In a terminal you would write:

git clone git://

This will download the repository in a directory named "amarok" on your machine.

Getting the work done

We create the FooClass.{cpp,h} files and start modifying them. Once we're satisfied, we're ready to commit the result. Since we have created new files, we need to add them to the repository:

git add FooClass.{cpp,h}

Good to go. Now we can commit the result.

git commit -m "Adding important FooClass for Amarok"

You obviously should change the message to what suits you more. Now, let's suppose that right when you are about to send the patch you find out about a small mistake in the file. Don't panic, just do your modification, and commit again (no need for git add this time)

git commit -am "Updating FooClass"

Don't worry about the 2 commits: git will handle that for you

Creating the patch

Ok, so our work is done and we just need to create the patches. It's really simple; just do

git format-patch origin

This command will create a set of patches out of all the commits you made since you cloned the repository. When running this command, you should be prompted a list of created files, one per commit. They should be named like <number>-commit-message.patch; so in our case git format-patch would create 0001-Adding-important-FooClass-for-Amarok.patch and 0002-Updating-FooClass.patch. Remember to send ALL the patches, and not just the last ones!

These patches contains also your commit information, so your name will appear in the commit log.

Sending the patch

You can now send the patch to ReviewBoard, to a developer, or using git send-email. The latter method will not be covered here since it needs some additional configuration. Please see git help send-email to learn more about it.

This page was last edited on 24 March 2012, at 19:44. Content is available under Creative Commons License SA 4.0 unless otherwise noted.