Multi-account git setup
If you work in software-related roles, it's likely that you can't do your work without git. Collaboration is going to be a very painful experience if you just store source code in a shared drive.
On initial setup, you'll get asked to enter your name and email to be used for a git commit. You can supply a random name or invalid email and it'll be fine, because these info are not used for verification, but rather for git commit metadata.
The fun starts when you also work for a company, where you are expected to use $companyEmail for company-related git operations. You can run git log (in a terminal, on your repo) to check which email is attached to your commits. You'd be surprised, just from random checks from my friends' repos, I've seen everything from $companyEmail, $studentEmail, $machineHostname. This means if you don't want your personal email to get exposed, you'll have to set your git email to [email protected] (this is for github, but other git forges - gitlab, codeberg, etc - should have something similar).
The git email itself is used when you view git history on git forges, it'll set a hyperlink back to your profile, assuming all your associated emails are added to your git forge profile.
To use different git name/email for each repo/groups, you can utilize git profiles. From my nix config, it looks like this:
# profiles/github
[user]
email = "[email protected]"
name = "Karn Wong"
signingkey = "ssh-ed25519 xxxxxxxxx [email protected]"And specify git profile to use per base directory:
includeIf."gitdir:~/Git/" = { path = "profiles/github"; };
includeIf."gitdir:~/Forgejo/" = { path = "profiles/forgejo"; };As long as you keep your personal and work repos in different base directories, it'll use the correct git name/email.
You can also set git config per repo, but I tend to work on multiple repos so this setup is less work for me.
But this begs the question - how can you be sure that a commit is actually created by the author and not someone impersonating them? Thankfully you can sign git commits, basically you can add gpg or ssh key as a signing key under your git forge settings. If you set up everything correctly, when you view a commit on git forge it should display something like "this commit is verified."