Git Tip: git config user.name and user.email for local (not global) config

Git is a source-control tool used by software developers.

As I’ve mentioned I’m just learning the ropes of Git and as someone doing that I’m going through a lot of tutorials that have a lot of similar-looking tips. One in particular is the use of:

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

These are also the default instructions from GitHub after you’ve created a repository. On my system I will actually be working with 2 GitHub accounts and many repositories among the two accounts – essentially 1 for personal projects and 1 for business projects where some projects are open sources (public repository) and other portions are not (private repositories).

What I wanted was to just have those settings on a per-repository basis and not set them globally. Searching around I came across an article on the Git basics that shows how to edit your .git/config file directly to add a [user] section with the information you want. While that’s easy enough, I just wanted to know how to do it from the command line without making it global… fortunately for me, it turned out to be easy as cheese:

git config user.name "Your Name"
git config user.email "you@example.com"

That’s right, just remove the ‘–global‘ and git will commit those values to the .git/config file for you (creating the [user] section if it’s missing). Keep in mind that Git determines the repository to write this information to based on the current directory you are in. It will hunt up the parent-directory-tree (including the current directory) for the first directory with a .git subdirectory, and then use that repository information. So you can be way down deep in a particular repository directory or at it’s root, but you can’t be “out” of it in a parent with no .git subdirectory.

Happy Git’ing!

Tags: , , , , , ,

About Riyad Kalla

Software development, video games, writing, reading and anything shiny. I ultimately just want to provide a resource that helps people and if I can't do that, then at least make them laugh.

, , , , , ,

2 Responses to “Git Tip: git config user.name and user.email for local (not global) config”

  1. Amway Global January 24, 2011 at 10:56 pm #

    Everyone find way about earn money from online. Also I am one of them. I have found many site about money making offer. But I very like Amway Global for additional income. “Amway Global” cares and encourages you to reach your goals. your goals are completely up to you.

Trackbacks/Pingbacks

  1. too useful not to re-post – git local usernames | - June 26, 2012

    [...] @ http://www.thebuzzmedia.com/git-tip-git-config-user-name-and-user-email-for-local-not-global-config/ This entry was posted in git, Linux, Source Code Management. Bookmark the permalink. ← [...]

Leave a Reply


9 − 8 =