DEV Community

Cover image for Have 2+ Jobs? Use Git without letting them know about each other
Dmitrii Pavlov
Dmitrii Pavlov

Posted on

Have 2+ Jobs? Use Git without letting them know about each other

(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:

Screen with a commit history and a TrollCoder nickname in it

😱 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
Enter fullscreen mode Exit fullscreen mode

If nothing is set globally, check your local project config:

git config user.name
git config user.email
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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 company abcdefg.

Step 3 — Create the config files

First, make a place to store them:

mkdir -p ~/.gitconfigs
Enter fullscreen mode Exit fullscreen mode

Personal config (~/.gitconfigs/.gitconfig-personal)

[user]
    name = Troll Coder
    email = troll.coder@gmail.com
Enter fullscreen mode Exit fullscreen mode

Work config (~/.gitconfigs/.gitconfig-abcdefg)

[user]
    name = John Smith
    email = john.smith@abcdefg.com 
Enter fullscreen mode Exit fullscreen mode

✅ 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)

Collapse
 
nathan_tarbert profile image
Nathan Tarbert

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

Collapse
 
pavlov-js profile image
Dmitrii Pavlov

Yeah, probably just us nerds. But better safe than leaking "AssCaptain" to prod)

Collapse
 
ildar_khabutdinov_22990e4 profile image
Ildar Khabutdinov

Thank you for this idea. I will use it in my work.

Collapse
 
_zainullin profile image
Eldar

Awesome! Great idea.
Gonna use it when needed. Thanks

Collapse
 
nicholasamsler profile image
Nicholas-Amsler

As someone brand new with under ten repositories and just starting out- I hope to have this issue one day!