DEV Community

Maintaining Different Git Identities

Max on July 02, 2017

I like to have separate "identities" for my private and work stuff when using Git: Commits at work should be authored with my work email and commit...
Collapse
 
denji profile image
Denis Denisov • Edited
case "$url" in
  *@github.com:*  ) email="my-public@email";    name="public name";;
  *//github.com/* ) email="my-public@email";    name="public name";;
  *@corp.com:*    ) email="my-corporate@email"; name="real name";;
  *//corp.com/*   ) email="my-corporate@email"; name="real name";;
esac

.gitconfig

[init]
  templatedir = ~/.git-templates

Collapse
 
stanislas profile image
Stanislas

That's even better 🥺 Thanks

Collapse
 
12s12m profile image
12s12m

Thanks this is really helpful. I used to manually edit the .git/config directory by appending the [user] information for every work related repo. This is a much better way :)

Collapse
 
plutov profile image
Alex Pliutau

Nice! Should it be changed?
From:

[includeIf "gitdir:~/Work/"]
path = .gitconfig-work

To:

[includeIf "gitdir:~/Work/"]
path = ~/.gitconfig-work

Collapse
 
maxlmator profile image
Max

It's not necessary to specify the full path. The path is relative to the location of the .gitconfig file itself, therefore it works in this case both ways.

But to make it easier to understand, the fullpath is probably a better example.

Collapse
 
engineercoding profile image
Wesley Ameling

Thank you so much for this!

Collapse
 
vberlier profile image
Valentin Berlier

Thanks, that's awesome!

Collapse
 
patwoz profile image
Patrick Wozniak

This is amazing. Thank you!

Collapse
 
cmmata profile image
Carles Mata

Very useful! I used to set git config every time I cloned a repo, so this must save a lot of time and headaches! Thank you

Collapse
 
maestromac profile image
Mac Siri

Nice, this is super useful. I didn't even know I needed this. Thank you!