💾 Archived View for home.hedy.dev › posts › multiple-emails-git.gmi captured on 2024-07-08 at 23:15:45. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2024-05-10)

-=-=-=-=-=-=-

Jun 16, 2021 (updated on Apr 13, 2024)

Multiple emails in git for different computers

As someone who code on multiple machines to work on different projects, I like to commit with different emails.

I don't know how everyone else handle different emails in .gitconfig *and* track dotfiles in a git repo at the same time, but here's the solution I've come up with.

First, I have a global ~/.gitconfig with the default user email and some other global settings (by global I mean same cross different computers I work on).

# ~/.gitconfig
[user]
    name = Default Name
    email = me@default.email

Then for each machine I have a ~/.gitconfig-local file which can override some settings just for that machine, such as email, signing key, editor, etc.

# ~/.gitconfig-local
[user]
    email = me@special.email

Back in the global ~/.gitconfig, I have this snippet that tells git to also look for configuration in my ~/.gitconfig-local:

# ~/.gitconfig
[include]
    path = ~/.gitconfig-local

Here, I can have ~/.gitconfig tracked in my dotfiles repo, but I do not have ~/.gitconfig-local tracked. This way, I can put anything I like specific to a particular machine in the ~/.gitconfig-local, as well as SMTP settings such as password, which you wouldn't want to end up in a public git repo.

As to setting it up on a new machine, I have a setup script in my dotfiles repo that creates an empty ~/.gitconfig-local. I use this same method with fish configs -- global config and a local config, you can have a look at them in my dotfiles repo on sourcehut:

https://git.sr.ht/~hedy/dotfiles/

EOF

Reply via email publicly (plain-text only)

Reply via email privately

247 words · #howto, #git

← Gemlog

← Capsule home

Source

View this page on the web

Capsule last rebuilt on 2024-05-01