Micron Document
Git and Email Patches

I saw a post about using git send-email (thank you Ploum!) and it looked like a thing I should know how to do.

I didn't actually have sendmail (or msmtp) installed on my development system. Crazy, right? I had been using protonmail for so long that I didn't bother. Mutt with proton uses the Protonmail bridge. So I had a little more setup to do to get ready.

On the sending side:

• added T383838msmtp to my system
• (test it to make sure sending works!)
• set the command for sending mail in .gitconfig
• make a change, commit it
• use git send-email

Then on the receiving side:

• download the patch
• invoke git am path-to-file

Dumb hiccups that got in the way:

• my server cert had expired (for just the mail subdomain)
• I copied Ploum's example (T383838/usr/bin/msmtp) which was wholely inappropriate for my nix box (T383838/run/current-system/sw/bin/msmtp)

T383838msmtp

I wanted to add T383838msmtp via home manager, but it didn't like the accounts block that I needed. So I put it in my configuration.nix.

T282828
programsTff7b72.Ta5d6ffmsmtp Tff7b72= Tb4b4b4{
Ta5d6ffenable Tff7b72= Tff7b72trueTb4b4b4;
Ta5d6ffsetSendmail Tff7b72= Tff7b72trueTb4b4b4;
Ta5d6ffdefaults Tff7b72= Tb4b4b4{
Ta5d6ffaliases Tff7b72= Ta5d6ff"Ta5d6ff/etc/aliasesTa5d6ff"Tb4b4b4;
Ta5d6ffport Tff7b72= T79c0ff587Tb4b4b4;
Ta5d6ffauth Tff7b72= Ta5d6ff"Ta5d6ffplainTa5d6ff"Tb4b4b4;
Ta5d6fftls Tff7b72= Ta5d6ff"Ta5d6ffonTa5d6ff"Tb4b4b4;
Ta5d6fftls_starttls Tff7b72= Ta5d6ff"Ta5d6ffonTa5d6ff"Tb4b4b4;
Tb4b4b4}Tb4b4b4;
Ta5d6ffaccounts Tff7b72= Tb4b4b4{
Ta5d6ffstephen Tff7b72= Tb4b4b4{
Ta5d6ffhost Tff7b72= Ta5d6ff"Ta5d6ffmail.thatit.beTa5d6ff"Tb4b4b4;
Ta5d6ffpasswordeval Tff7b72= Ta5d6ff"Ta5d6ffpass show stephen@thatit.beTa5d6ff"Tb4b4b4;
Ta5d6ffuser Tff7b72= Ta5d6ff"Ta5d6ffstephen@thatit.beTa5d6ff"Tb4b4b4;
Ta5d6fffrom Tff7b72= Ta5d6ff"Ta5d6ffstephen@thatit.beTa5d6ff"Tb4b4b4;
Tb4b4b4}Tb4b4b4;
Tb4b4b4}Tb4b4b4;
Tb4b4b4}Tb4b4b4;


I didnt want the default mail to be mine, so I used my username instead of default. Invocations to send mail will need to specify that as the account.

pass

Coincidentally, I did have my password already saved in pass.

Speaking of pass, pass requires gnupg and setting that up has a few weird things if you don't want it to use a gui. Details on that can be found in From Zero to Protonmail -- see the configure pass section. Take note of the pin-entry option. Note that pass will prompt for a password if the key that was used in the init has a pass.

A T383838nixos-rebuild switch later and I was ready to send a test message.

test msmtp

T282828
Tffa657echo -e Ta5d6ff"Content-Type: text/plain\r\nSubject: Test\r\n\r\nHello World" Tb4b4b4| sendmail -a stephen some-other-address@example.com


And it all worked first try... is a thing I could say if my mail server cert hadn't expired three days ago. So a quick T383838nixos-rebuild switch over there (I had pending changes anway) and then it all worked fine on the second try.

set the command for sending mail in .gitconfig

I edited my T383838.gitconfig directly like some kind of cowboy.

[sendemail]
sendmailCmd = msmtp --set-from-header=on -a stephen
envelopeSender = auto

make a change, commit it

I used one of mine, but any repo will do. Clone a repo. Make a change. Commit the change.

use git send-email

git send-email HEAD^1

And then things got tricky. It parses sender information from the patch. I always have my email set to T383838stephen@<> in commit messages, so I had to choose T383838d for for drop when it asked what I wanted to do with the address. And then I had to hit it again because it wanted to cc me twice.

But then it sent!

download the patch

In mutt, v for viewing, s for saving.

I saved it as T383838~/Downloads/test-path

invoke git am path-to-file

In a fresh checkout of the project where I had made the change (but not one that has the change), I ran the command:

T282828
git am ~/Downloads/patch

The patch was applied. Everything went (relatively) smoothly.

I can now use email to send patches from the CLI.

Tags: index, cli, git

Tags
Navigation





created: 2026-02-05

(re)generated: 2026-07-17