(or just want to separate work and personal projects)
Let’s say you’ve been using GitHub under your personal identity — maybe something like TrollCoder
. Everything’s been smooth until you get hired, they give you a corporate email, and set you up with a company GitHub or GitLab account.
Suddenly, you're expected to use your real name and photo in commit history — but your next commit to a work project shows up as TrollCoder
:
😱 Awkward. Especially if your Git identity shows ties to a different company...
Bottom line: if you work for multiple clients or just want clean separation between personal and professional activity — it's crucial to manage Git identity per project.
A few Git facts:
- Git stores your name and email globally.
- This info ends up in every commit.
- Unless configured correctly, you risk leaking personal info into work repos (and vice versa).
Let’s fix that.
Step 1 — Check your current Git identity
git config --global user.name
git config --global user.email
If nothing is set globally, check your local project config:
git config user.name
git config user.email
Step 2 — Use conditional Git configs per folder
The idea is to define separate Git profiles depending on the folder path.
Let’s say you work for a company called abcdefg
. In your ~/.gitconfig
, add:
[includeIf "gitdir:~/mydevfolder/"]
path = ~/.gitconfigs/.gitconfig-personal
[includeIf "gitdir:~/mydevfolder/abcdefg/"]
path = ~/.gitconfigs/.gitconfig-abcdefg
What’s happening here:
- Any repo under
~/mydevfolder/
will use your personal Git config. - Repos under
~/mydevfolder/abcdefg/
will use your work Git config for companyabcdefg
.
Step 3 — Create the config files
First, make a place to store them:
mkdir -p ~/.gitconfigs
Personal config (~/.gitconfigs/.gitconfig-personal)
[user]
name = Troll Coder
email = troll.coder@gmail.com
Work config (~/.gitconfigs/.gitconfig-abcdefg)
[user]
name = John Smith
email = john.smith@abcdefg.com
✅ Now anytime you commit inside a project under abcdefg
, Git will correctly attribute the commit to your work identity — no more accidental TrollCoder
showing up in corporate history.
Wrap-up
This setup helps you avoid identity leaks between work and personal repos, keeps your commit history clean, and saves you from embarrassing mistakes — especially if you freelance or contribute to OSS on the side.
If you found this helpful, give it a ❤️ and share it with your team.
Top comments (5)
perfect walkthrough, honestly been wanting a setup like this forever tbh you think most folks ever care about commit history outside open source or is it just us nerds
Yeah, probably just us nerds. But better safe than leaking "AssCaptain" to prod)
Thank you for this idea. I will use it in my work.
Awesome! Great idea.
Gonna use it when needed. Thanks
As someone brand new with under ten repositories and just starting out- I hope to have this issue one day!