Using Git to patch drupal modules

As a Drupal Developer, I often find myself needing to submit patches back to One easy way to do this is to use git. Because git is a distributed version control, it can just be used locally. This is perfect for making a quick patch.

Here is how I go about doing it. I enter the module dir (this is one of the nice things that I do not have to worry about getting it from cvs). then I init git and add the files i need (or all for good measure) and do a commit

git init && git add * && git commit -m "start"

Then i can make my changes and generate patch by doing

git diff --no-prefix >MODULE-TRACKINGNUMBER.patch

If I am removing or adding files one needs to add them to git and then add any files that you have changed and run git diff with the --cache option (this is a diff between HEAD and any what is to be commited. for example lets say i am adding an inc file to a module and so i need to add that file and edit the .module file:

git add
git add MODULE.module
git commit --no-prefix --cache >MODULE-TRACKINGNUMBER.patch