I use my personal laptop for both work and personal projects and I would like to use my work email address for my commits at work (gitolite) and my personal email address for the rest (github).
I read about the following solutions which are all either global or temporary:
git config --global user.email "bob@example.com"
git config user.email "bob@example.com"
git commit --author "Bob <bob@example.com>"
- setting one of the
GIT_AUTHOR_EMAIL
,GIT_COMMITTER_EMAIL
orEMAIL
environment variables
One solution is to run manually a shell function that sets my environment to work or personal, but I am pretty sure that I will often forget to switch to the correct identity resulting in committing under the wrong identity.
Is there a way of binding a certain repository, project name, etc. to an identity (name, email)? What do people do?
Edit the config file with in ".git" folder to maintain the different username and email depends upon the repository
This below command show you which username and email set for this repository.
Example: for mine that config file in D:\workspace\eclipse\ipchat\.git\config
Here ipchat is my repo name
git config user.email "bob@example.com"
Doing that one inside a repo will set the configuration on THAT repo, and not globally.
Seems like that's pretty much what you're after, unless I'm misreading you.
As of Git 2.13 you can use an
includeIf
in your gitconfig to include a file with a different configuration based on the path of the repository where you are running your git commands.Once I get it working myself I'll update with a better example.
https://motowilliams.com/conditional-includes-for-git-config#disqus_thread
To use Git 2.13 you will either need to add a PPA (Ubuntu/Debian) or download the binaries and install (Windows/other Linux).
If you don't use the
--global
parameter it will set the variables for the current project only.If you use
git config user.email "foo@example.com"
it will be bound to the current project you are in.That is what I do for my projects. I set the appropriate identity when I clone/init the repo. It is not fool-proof (if you forget and push before you figure it out you are hosed) but it is about as good as you can get without the ability to say
git config --global user.email 'ILLEGAL_VALUE'
Actually, you can make an illegal value. Set your
git config --global user.name $(perl -e 'print "x"x968;')
Then if you forget to set your non-global values you will get an error message.
[EDIT] On a different system I had to increase the number of x to 968 to get it to fail with "fatal: Impossibly long personal identifier". Same version of git. Strange.
You need to use the local set command below:
local set
local get
The local config file is in the project directory:
.git/config
.global set
global get
The global config file in in your home directory:
~/.gitconfig
.Remember to quote blanks, etc, for example: 'FirstName LastName'