Using Git with Multiple Email Addresses

Has this ever happened to you?

  • Gitlab commits are logged in your personal account but not on your work account (and vice versa) - but they seem to work correctly on your self-merged MRs.
  • Gitlab activity doesn't seem to log the days you're sure you've contributed code. and who is firefire199469 (and apparently this is your secret Gitlab). And why are you merging his commits?
  • Work Slack Gitlab notifications don't show your profile picture.

This is because you configured your git to use these user profiles globally.

# bash
$ git config --global user.email "personal@email.com"
$ git config --global user.name "Bob Ong"

Now you're always personal@email.com in all your commits on all projects.

To fix this, you can set your user profile on a git repository level.

# bash
$ cd $HOME/Projects/workproject
$ git config user.email "work@email.com"
$ git config user.name "Jesse Panganiban"

$ cd $HOME/Projects/secretproject
$ git config user.email "secret@email.com"
$ git config user.name "Dude Dude"

You get the idea.

Show Comments

Get the latest posts delivered right to your inbox.