Drupal is using CVS for version controlling core and contrib modules. CVS has diffing options, but it becomes annoying when you try adding or deleting new files. Here’s an example of how to use git to patch a contrib module - Organic groups.

  1. In OG's project page click on the CVS instructions and select the version you want to patch. ``` cvs -z6 -d:pserver:anonymous:[email protected]rupal.org:/cvs/drupal-contrib checkout -d og-DRUPAL-6--2 -r DRUPAL-6--2 contributions/modules/og/ ```
  2. Go inside the directory you just checked out from CVS. ``` cd og-DRUPAL-6--2 ```
  3. Make the folder and all sub-folder a git repository, and add all the files. ``` git init git add . git commit -m "Initial commit of the Organic groups module." ```
  4. No we have a _master branch with the original module. We can create a new git branch and work on this new branch - edit files, move files around, create new directories, etc'. ``` git checkout -b new-branch ```
  5. The _new-branch is now the active branch. Do some changes to code, and commit them. ``` git commit -a -m "A meaningful commit description." ```
  6. In order to create a diff file, we need to switch back to the master branch, and create a diff against our new-branch. Note that we use the ```--no-prefix``` command to follow the patch creation standard of Drupal. ``` git checkout master git diff --no-prefix master new-branch > [issue-id]-[patch description]-[comment number].patch ```
  7. We can delete the temporary branch. ``` git branch -D new-branch ```

If you want to work only with git, and skip the CVS part, have a look at git.drupalfr.org.