Setting Up Your Global Git Config File

September 17, 2018 by Michael

The first things you should do after installing Git on a computer is setup your global username and email config. The git config command can be used to manage these settings.  The --global option allows you to set these values for all repositories while --local limits the value to your current repository.

Here are a few common examples:

git config --global user.name "John Doe"
git config --global user.email john.doe@something.com

To confirm that the values have been properly set, you can use the config command without a value.  For example:

git config --global user.name

The global .gitconfig file also allows you to setup aliases.  As an example, I don’t care for the default output format when using the git log command.  To work around this, I setup the following global alias:

git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %Cblue<%an>%Creset' --abbrev-commit --date=relative --all"

The format of the git config command is fairly straight forward:

git config [--global|--local] section.setting value

Note, you do not need to specify the –local option:  it will be used by default if –global is not specified.

On Unix systems you will need to wrap the value in single quotes if the value has a space in it.  On Windows systems you will need to use double quotes if the value has a space.

If you find editing your .gitconfig settings one-by-one a bit tiresome, you can always open up the file and edit it directly.  On Unix systems you can find the configuration file in your user’s home directory: ~/.gitconfig.  On Windows systems you can find it here: C:\Users\[username]\.gitconfig (Command Prompt) or C:\Users\[username]\babun\cygwin\home\[username]\.gitconfig (Babun)

Editing this file directly could result in a broken configuration, therefore you should  edit with caution.

Useful Links

For more information about managing your .gitconfig file, refer to the following links about the git config command:


Leave a Reply

Your email address will not be published. Required fields are marked *