Scripting/Programming

Multiple Git Repositories Multiple Emails

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

 

 

 


  1. https://orrsella.com/2013/08/10/git-using-different-user-emails-for-different-repositories/
  2. https://github.com/git/git/commit/c37f9a1bc38cad56c9eca40014802e7cd822c21c
  3. The global config will display the user.name and user.email from the global .gitconfig in the output from git config --list. This is why we want to first remove the user.email from the global .gitconfig.

Case Insensitive List (ls)

When I’m using a Unix-like terminal I don’t always remember the full name of a directory or file.  In a Unix-like world, file and directory names are case sensitive.

Sometimes the system we are logged into is not always our own and therefore not customized with default settings.  In these situations the following knowledge can be helpful.

ls -Fd [Vv]*

Using the standard list command we get the following,

case-insensitive-ls-1

Here is the same directory listing using the case insensitive approach,

case-insensitive-ls-2

I use the -F switch to identify which items in the output are directories.  The formal definition of the -F switch is,

Display a slash (`/’) immediately after each pathname that is a directory, an asterisk (`*’) after each that is executable, an at sign (`@’) after each symbolic link, an equals sign (`=’) after each socket, a percent sign (`%’) after each whiteout, and a vertical bar (`|’) after each that is a FIFO.

I use the -d switch to tell Bash I do not want to recursively descend into directories.  The formal definition of the -d switch is,

Directories are listed as plain files (not searched recursively).

The example above along with the definitions are from OS X 10.9.1