Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Wednesday, July 13, 2016

How to tell git to use the correct identity (name and email) for a given project?

How to tell git to use the correct identity (name and email) for a given project?


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 "
  • setting one of the GIT_AUTHOR_EMAIL, GIT_COMMITTER_EMAIL or EMAIL 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?

Answer by Seth Robertson for How to tell git to use the correct identity (name and email) for a given project?


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.

Answer by ismail for How to tell git to use the correct identity (name and email) for a given project?


If you don't use the --global parameter it will set the variables for the current project only.

Answer by Dan Ray for How to tell git to use the correct identity (name and email) for a given project?


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.

Answer by arulraj.net for How to tell git to use the correct identity (name and email) for a given project?


Edit the config file with in ".git" folder to maintain the different username and email depends upon the repository

  • Goto Your reposotory
  • Show the hidden files and goto ".git" folder
  • Find the "config" file
  • Add the below lines at EOF

[user]

name = Bob

email = bob@example.com

This below command show you which username and email set for this repository.

git config --get user.name

git config --get user.email

Example: for mine that config file in D:\workspace\eclipse\ipchat\.git\config

Here ipchat is my repo name

Answer by Mahmoud Zalt for How to tell git to use the correct identity (name and email) for a given project?


You need to use the local set command below:

local set

git config user.email mahmoud@company.ccc  git config user.name 'Mahmoud Zalt'  

local get

git config --get user.email  git config --get user.name  

The local config file is in the project directory: .git/config.

global set

git config --global user.email mahmoud@zalt.me  git config --global user.name 'Mahmoud Zalt'  

global get

git config --global --get user.email  git config --global --get user.name  

The global config file in in your home directory: ~/.gitconfig.

Remember to quote blanks, etc, for example: 'FirstName LastName'


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.