Git‎ > ‎

Configuring Git

Git stores its configuration in two places: a global configuration file and a config file inside a repository.  On Linux systems, the global file is located at ~/.gitconfig and inside of a repository the config file is at .git/config.

When first setting up git, you should set your name and email address.  It is suggested that you do this globally so that all projects you create and clone won't need to be individually configured.  Run these commands:

git config --global user.name "Firstname Lastname"
git config --global user.email "you@example.com"

It is also suggested that you enable the autosetupmerge option so that when you work on branches, you will not need to specify the --track option when we pull and push.  This also avoids the need to manually merge remote tracking branches with fetch and then merge.  Also, you might need to specify the second setting so you can push back to origin correctly.

git config --global branch.autosetupmerge true
git config --global push.default matching

If you decide to colorize things, I feel that the default colors can be a bit hard to read.  You might like these a bit more.  Edit your ~/.gitconfig file and add these lines.  If you look closely at that file, you'll see what the "git config --global" commands changed.

[color]
ui = true
branch = auto
interactive = auto
diff = auto
status = auto
[color "branch"]
current = yellow reverse
local = yellow
remote = green
[color "diff"]
meta = yellow bold
frag = magenta bold
old = red bold
new = green bold
[color "status"]
added = yellow
changed = green
untracked = cyan

And now you have colors.  Moreover, you now know how to edit your global git config file.  The config file inside each repository can individually override anything in your global config, so if you need to commit as "Tyler Akins" most of the time, but you want to commit as "Reverend T. Akins" for a particular project, you can do that.

For more configuration options, perhaps take a peek at understanding aliases.
Comments