Skip to content

Instantly share code, notes, and snippets.

@harilvfs
Created April 28, 2025 16:34
Show Gist options
  • Select an option

  • Save harilvfs/6d81b9c5309150434a420b73ff2ae55f to your computer and use it in GitHub Desktop.

Select an option

Save harilvfs/6d81b9c5309150434a420b73ff2ae55f to your computer and use it in GitHub Desktop.
How to Send Git Patches Using Git Send-Email

How to Send Git Patches by Email (Simple Guide)

This is a simple and correct guide for setting up git send-email and sending patches over email.


1. Why Send Patches by Email?

  • It's fast, lightweight, and works everywhere.
  • It leaves a good record (every patch = an email = permanent).
  • Some projects prefer email over pull requests.

2. Tools You Need

  • git
  • git send-email
  • An SMTP server (your email provider) to send emails
Distro Install Command
Ubuntu/Debian sudo apt install git-email
Fedora sudo dnf install git-email
Arch Linux Already included with git

3. Set Up Your Git Identity

Set your username and email:

git config --global user.name "Your Name"
git config --global user.email "[email protected]"

4. Set Up SMTP for Sending Emails

Configure SMTP settings so Git can send the patches.

git config --global sendemail.smtpServer smtp.yourprovider.com
git config --global sendemail.smtpUser [email protected]
git config --global sendemail.smtpServerPort 587
git config --global sendemail.smtpEncryption tls

Notes:

  • Gmail SMTP: smtp.gmail.com
  • Outlook SMTP: smtp.office365.com
  • ProtonMail (Bridge): 127.0.0.1

If you skip smtpPass, Git will ask for your password when sending.


5. Create a Patch

After committing changes, create a patch file:

git format-patch -1 HEAD

This generates a patch file like 0001-some-change.patch.

If you have multiple commits you want to send:

git format-patch -N HEAD

where N is the number of commits you want.

Example: to create patches for the last 3 commits:

git format-patch -3 HEAD

6. Find Maintainers (Optional)

If you need to send patches to the right people, you can use a script (if available in the project) like:

./scripts/get_maintainer.pl 0001-some-change.patch

(This is optional; depends on the project.)


7. Send the Patch

Send the patch using email:

git send-email --to [email protected] 0001-some-change.patch

If you're sending multiple patches, you can send them all at once:

git send-email --to [email protected] 000*.patch

You can CC others using --cc.


8. Add a Cover Letter (Optional but Nice)

If you're sending multiple patches, it's good practice to send a short "cover letter" email explaining what the patch series does.

Create the patches with:

git format-patch -N --cover-letter HEAD

This will create a 0000-cover-letter.patch you can edit before sending.

Then send all patches including the cover letter:

git send-email --to [email protected] 000*.patch

9. Test Sending First

Always dry-run first to check if everything works:

git send-email --dry-run --to [email protected] 0001-some-change.patch

10. Bonus: Password Handling

If you don't want to store your SMTP password:

git config --global sendemail.smtppass dummy

Git will then ask for your password each time you send.


11. Good Email Habits When Sending Patches

  • Always set a good subject line for your patches (explain the change briefly).
  • Write a good commit message (title + body).
  • CC relevant maintainers or mailing lists if needed.
  • Reply to feedback and be polite.
  • If you resend patches (v2, v3, etc.), mention version in the subject line.

Example subject for v2:


12. How to Send v2, v3 (Updated Versions)

If you get feedback and need to send a corrected patch:

  1. Make the fixes.
  2. Create a new patch (using git format-patch).
  3. Add version info manually in subject line or with options like:
git format-patch -v2 -1 HEAD
  1. Send again using git send-email.

Important: When sending v2, v3, etc., reply in the same email thread if possible. Use --in-reply-to option with the Message-ID of the previous email.

Example:

git send-email --in-reply-to="[email protected]" 0001-new-fix.patch

13. Quick Summary Diagram

[git config user.email] --> sets your From: address
[git config sendemail.smtpServer] --> sets SMTP settings
[git format-patch] --> creates patch files
[git send-email] --> sends patch files over SMTP

References

@harilvfs
Copy link
Author

If I have missed something or included any wrong info, you are welcome to correct me. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment