💾 Archived View for hedy.smol.pub › multiple-email-git-config captured on 2023-01-29 at 02:16:53. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2022-06-03)

➡️ Next capture (2024-06-20)

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

hedy.smol.pub

` `  ` '  `   `   ` ` ` `  `    `  ` ' `  ` ` ` '   `  ' ` ` ' ` 

Managing multiple emails for git across different computers

NOTE: An updated version of this post is on my blog:

https://hedy.tilde.cafe/posts/multiple-emails-git/

---

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). Then for each machine I have a ~/.gitconfig-local file which can override some settings just for that machine.

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

[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/

` `  ` '  `   `   ` ` ` `  `    `  ` ' `  ` ` ` '   `  ' ` ` ' `