💾 Archived View for hedy.tilde.cafe › posts › multiple-emails-git.gmi captured on 2023-11-04 at 11:30:25. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-09-08)

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

Managing multiple emails for git across different computers

Posted 2021-06-16

Last updated 2022-05-15

Tags: git, howto

--

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/

--

Questions/comments:

Public gemlog mailing list (plain-text only)

Or email me directly

Home

Source

View this page on the web

Capsule last rebuilt on 2023-08-27