Friday, January 13, 2012

How to send patches via git-send-email

In the past I either directly commited to git or send - if needed - my patches to e.g. mailing list by exporting the patches from my local git repo via 'git format-patch -s origin' and then importing them into my mailer. Yesterday I finally found some time to get git-send-email running to do this for me directly on command line.

First you have to choose if you always use the same email account to send your patches. In this case you need to configure 'git-send-email' this way:
git config --global sendemail.from "YOUR NAME <>"
git config --global sendemail.smtpserver
git config --global sendemail.smtpuser USER
# depending on your config you may also set:
git config --global sendemail.smtpencryption tls
If you don't want to enter password for your SMTP server all the time:
git config --global sendemail.smtppass = PASS
If you use different settings/email accounts for different project, you can setup different identities for them. Here one example for btrfs project:
git config --global ""
git config --global sendemail.btrfs.from "YOUR NAME <>"
git config --global sendemail.btrfs.smtpserver
git config --global sendemail.btrfs.smtpuser USER
git config --global sendemail.btrfs.smtppass = PASS
git config --global sendemail.btrfs.smtpencryption tls
There are some other options you may should use as e.g.:
git config --global sendemail.chainreplyto false
to set the threading format to shallow/flat instead of the deep threading, which is much more readable on a mailing list if you send multiple patches at once.

Now you can send you patches with (you may have to replace origin with the revision you need):
git send-email --annotate origin
If you use an identity e.g.:
git send-email --identity=btrfs --annotate origin
If you didn't commit your changes into your local git branch with the -s option (to get the 'Signed-off-by:' line) you need to add the --signoff option, as I realized after sending my latest patches to the btrfs mailing list. If you send a patch series you may also want to use a cover email to explain something or to write more info. In this case you can use --cover-letter to get git to create and let you edit such an email before sending. 

Here the full example command I would use to send my patches:
git send-email --identity=btrfs --annotate --cover-letter --signoff origin
For more info check e.g. the Git Community Book or use your favorite internet search engine.

No comments: