How to create patch in Drupal through Git

From last 2 months, i am solving issues on D.O( Some of them were just documentation work with screenshots.
Finally i got an issue of patching, then i came to learnt about patching in drupal.
Let us discuss how patching done in drupal module:
1. Go to site/all/modules directory if you are patching a module.
2. Download the specific version of module or we can say that branch of module(i.e. 7.x-3.11 or may be 7.x-3.x).

git clone --branch 7.x-1.x
cd module_name

3. Check the branch of module you have just cloned in your local system.

git branch

it will show something like it


4. Now create a new branch named it as issue_number-description_of_issue.

 git checkout -b issue_number-issue_name

For example

 git checkout -b 1234-typo_error

5. Check the newly created branch

 git branch 

Output will be like this


6. Switch to new branch with following command

 git branch 1234-typo_error

Check current branch :

 git branch 

Output will be like this


7. Do the changes in the files as you want.
8. Create patch with following command

git diff 7.x-1.x > [project_name]-[short-description]-[issue-number]-[comment-number]-[drupal-version].patch

For example :

git diff 7.x-1.x > views-typo_error-1234-4-7.39.patch

9. Upload patch on and specify your valid comment.
Please comment or get in touch for any query.
Happy Patching :)