Remote Software Engineer at Stripe and cellist based out of Ontario. Previously at GitLab. Fascinated with building usable, delightful software.
August 26, 2021 | 2 minutes to read
Juggling multiple Git identities can be tricky.
For example, at Stripe, we encourage developers to create a separate GitHub account for Stripe-related open source activity. For me, this means I now own both a nfriend
and a nfriend-stripe
GitHub profile.
While setting up my dev environment, I had a few goals:
Good news! This is possible with a little .gitconfig
magic ✨
Note: The instructions below rely on Git’s conditional includes, which are only available in Git 2.13 and beyond.
I won’t go into details since this is already covered in great detail by other tutorials. GitHub’s tutorials are particularly well-presented:
For example, a ~/github-personal
and a ~/github-work
directory.
.gitconfig_include
file in eachInside each of these new directories, create a new file named .gitconfig_include
with the following content:
[user]
name = Your Name
email = your-name@example.com
signingkey = 0123456789ABCDEF
[core]
sshCommand = ssh -i ~/.ssh/id_rsa_example -F /dev/null
Update each file with the name, email, and signing key for the corresponding Git identity.
Additionally, update the command in the sshCommand
option to reference the appropriate key file.
.gitconfig
In your global .gitconfig
(i.e. ~/.gitconfig
), configure Git to conditionally include the correct .gitconfig_include
file based on the current directory:
[includeIf "gitdir:~/github-personal/"]
path = ~/github-personal/.gitconfig_include
[includeIf "gitdir:~/github-work/"]
path = ~/github-work/.gitconfig_include
Create a test project with both identities. Ensure you can:
If you’re using a web UI like GitLab or GitHub, check to see that your commits are being signed correctly and are labeled as “Verified”:
Some things I found helpful while setting this up:
.gitconfig
settings on a per-directory basis: https://stackoverflow.com/a/48088291/1063392core.sshCommand
configuration to select an SSH key: https://superuser.com/a/912281/144803Thoughts? Let me know in this GitLab issue!
Other posts you may enjoy:
May 31, 2024 | 6 minutes to read
June 26, 2023 | 14 minutes to read
January 25, 2022 | 6 minutes to read
May 7, 2021 | 1 minute to read
November 18, 2020 | 6 minutes to read