Thought I'd share how I'm configuring
user.email for git on my work computer. This is really just a post so when I forget how I did in the future I can google my own blog and be reminded...
I have always struggled with accidentally committing to an OSS project my work name/email or visa-versa, committing to a work git repo with my personal name/email.
user.name shouldn't change, unless your company ties your
user.name to something specific to the company like a username. (Contrast:
user.name = Jason Jarrett and
user.name = jjarrett).
When I clone projects I always clone them into a folder structure that looks like
|____~/code | |____personal/ <--- this is where I would put some OSS projects that I may be working on or contributing to. | |____work/ <--- obviously work code goes in here
brew install direnv(What about Windows? see this github issue and help make it work)
.envrcfile for each profile needing to be setup with the following content
export GIT_AUTHOR_EMAIL=<your email> export GIT_AUTHOR_NAME=<your name> export GIT_COMMITTER_EMAIL=<your email> export GIT_COMMITTER_NAME=<your name>
After installing and setting the
direnvwill prompt to use the env file which we accept by running
Now I should have the following structure
|____~/code | |____personal/ | |____.envrc <-- env settings with personal git user/email | |____work/ | |____.envrc <-- env settings with work git user/email
What did this do?
Each time we
cd into either a
direnv will setup our shell with environment variables contained in that folder's
.envrc file. This will then allow Git which respects these env vars and now we don't have to think about committing the wrong name/email to the wrong Git repositories.