Open In App

How to send Email using Git send-email via Gmail?

Last Updated : 18 Mar, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

The first and the foremost question that comes to mind is why do we really need to send patch emails to contribute to an open source project instead of just creating a pull request. The answer is very simple as some organizations want you to contribute to their project by making changes and sending those changes in the form of patches via email.

What is a patch? A patch is a small file that indicates the changes made in a repository. It’s generally used when someone from outside your team has read-only access but had a good code change available. He then creates a patch and sends it to you.

Note: This tutorial is based on Ubuntu and expect you already have git installed in your system, if not you can check this tutorial on how to install git.

Step 1: We will get started with installing the required package, git-email. This package is required in order to send the patch via email. To do this open any terminal of your choice and type in the command:

sudo apt-get install git-email

Step 2: Configure your global git config file in order to send emails using git. To do this type in the following command in your terminal and it will open the git config file in your default browser.

git config --global --edit

Step 3: Update the configuration file with the following details: 

...
...
[sendemail]
    smtpserver = smtp.googlemail.com
    smtpencryption = tls
    smtpserverport = 587
    smtpuser = youremail@gmail.com

Note: Don’t forget to change youremail@gmail.com with your actual email address.

And after editing the file same the file and quit the editor.

Step 4: Now this is one of the most import step as in this step we will be creating a .patch file. In order to create a patch you have to modify or make some changes to the repository that you want to contribute to and after making those changes, simple save those files and type this commands to create a patch.

git add .
git commit -m "your message"
git format-patch --to=senderemail@gmail.com HEAD~..HEAD

Note: The HEAD~ option tells git to create the patch of the latest commit only but if you want to create a patch of your last two commits then simply change HEAD~ to HEAD~2.

As you can see after successfully running those commands, a patch file is generated, and we will send this file using git send-email.

Step 5: Once we have the .patch file we can send this patch file to the person maintaining the repository or the one to whom the message is intended to be sent. To do this run the following command:

git send-email *.patch --to=receiver@gmail.com --cc=carboncopy@gmail.com

Note: Don’t forget to update the –to option and the –cc option with actual email addresses.

Once you run this command, git will ask for your Gmail password so Enter your password and you will get a success message once a message is successfully sent.

That’s it. Now wait for it to get reviewed and once reviewed and found valid your contribution will be successful.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads