Git Configuration

Introduction

This page contains a quick reference of the commands needed to configure a Git repository. This page is part 1 of the Git quick reference series:

Git Configuration

Git requires some configuration to control how Git looks and operates. Some configuration variables are vital, such as user.name  and user.email . Others are just personal preferences such as color.diff  or core.editor .

There are three types of Git configuration: repository, user and system-wide configurations. It is a hierarchical model, that is, the repository configuration overrides the user configuration.

  • .git/config . Repository configuration
  • ~/.gitconfig or %HOME%/.gitconfig . User specific configuration.
  • /etc/gitconfig  or %GIT_HOME%/etc/gitconfig . System-wide configuration

The git config tool manages the Git configuration. When using --system  it targets the system-wide configuration. When using --global  it targets the user specific configuration. When using --local  or no flag it targets the repository configuration.

Configure Who We Are

We must configure our username and email before committing to Git. We use --global  to set the username and email for all Git projects.

List Git Configuration Variables

To list the configuration variables applicable to a Git repository:

To list the configuration variables applicable to a specific configuration area:

 Set Git Editor

Some commands such as commit and tag let you edit messages.

Set Git Diff Tool

The diff.tool  variable controls the tool used to compare files. There are some predefined diff tools:

To use another non-predefined diff tool, we need to use the difftool.<tool>.cmd  variable:

Set Colors

Set the color.ui  variable to auto to turn on colours whenever possible.

Configuring an Alias

Aliases are useful to create easy to remember commands that execute long to type Git commands.

Now we can run the aliased command as if it was any other git command

These are some useful aliases:

A Suggested Basic Git Configuration

Below a suggested configuration you need to get up and running in a new Git configuration.

Bibliography

  • Git Reference: http://git-scm.com/doc
  • Pro Git. Scott Chanon and Ben Straub. APress. http://git-scm.com/book/en/v2
  • Pragmatic Guide to Git. Travis Swicegood. Pragmatic Bookshelf, 2010.
  • Version Control with Git. Jon Loeliger and Mattew McCullough. O’Reilly, 2012

Git Tools

The following two tabs change content below.

Eduard Manas

Eduard is a senior IT consultant with over 15 years in the financial sector. He is an experienced developer in Java, C#, Python, Wordpress, Tibco EMS/RV, Oracle, Sybase and MySQL.Outside of work, he likes spending time with family, friends, and watching football.

Latest posts by Eduard Manas (see all)

Leave a Reply