12/28/2021 Note: corrected code block format
I’m using multiple git repositories for various work related and personal related projects.
Recently I was working with a repository at work and notice my personal email address in the commit log. Well, this wasn’t cool. I mean my personal email is awesome, but having it appear in work related commit log was… well not cool.
My .gitconfig
had the following parameters set correctly for my personal Git repositories.
[user]
name = Boogy Man
email = boogyness@datagram.io
The command git config --list
can be used to view a list of defined values for a Git config. Run this command from anywhere within the system.
If your command prompt resides in a cloned git repository, the command output from git config --list
will include the output from the .gitconfig
plus any local values in the .git/config
file of that cloned repository.
Also, using anyone of the cat
, less
, more
or favorite editor will achieve the same result.
Others 1 have run into the same, having multiple repositories – professional and personal. Thankfully, Git was updated 2 to resolve the matter as Orr Sella points out in his blog post.
The .gitconfig
is the global config that resides outside of any repositories. Each git repository has it’s own config
file within it.
/path/home_dir/.gitconfig
/path/home_dir/some_dir/git_clone_dir/.git/config
Replacing the email = boogyness@datagram.io
stanza in the .gitconfig
will influence Git to prompt for a name and email on a per repository basis. This of course will occur one time that repository and there after the user name and email will be recored within the repository’s config
file.
first step: Updating the global git config first 3,
shell$ cd ~
shell$ git config --global user.useConfigOnly true
shell$ git config --global --unset-all user.email
second step: Then moving into the work repository the following is performed to set the work related email ,
shell$ cd /some_dir/git_clone_dir
shell$ git config user.email "serious@professional.com"
shell$ git config --list
The same will be done on any other local repository.
note: If just updating the git global .gitconfig
is all you do, and skip setting the then the following git message will appear when you run git commit
.
git commit
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: no email was given and auto-detection is disabled
- https://orrsella.com/2013/08/10/git-using-different-user-emails-for-different-repositories/ ↩
- https://github.com/git/git/commit/c37f9a1bc38cad56c9eca40014802e7cd822c21c ↩
- The global config will display the
user.name
anduser.email
from the global.gitconfig
in the output fromgit config --list
. This is why we want to first remove theuser.email
from the global.gitconfig
. ↩
Comments