Git Config - Customising the Git environment

Git

Share

In this tutorial we will learn to configure Git.

The config tool

Git has a tool called git config to customize the Git environment. It lets us to get and set the configuration variables.

The config levels

We can set the configuration at three level.

  • system
  • global
  • local

The global config will override the system level config. The local config will override the config set at the global and sytem level.

Git config --system

This configuration is applied across an entire machine covering all users of the operating system and all repositories.

System level configuration resides in gitconfig file under system root on Unix system.

Example:

/etc/gitconfig

Git config --global

This configuration is applied to an operating system user and resides in a .gitconfig file under user directory.

Example:

/Users/yusufshakeel/.gitconfig

Git config --local

This configuration is applied to a repository. And it is a default configuration if no option is mentioned.

Example:

/Users/yusufshakeel/GitHub/dyScrollUpJS/.git/config

Setting user name and email

After installing Git the first thing we need to do is set the user name and email address. This two information is used in every Git commit. More on commit later.

This setting is done once using the --global option.

To set the user name at the global level we use the following command.

$ git config --global user.name "Yusuf Shakeel"

To set the user email at the global level we use the following command.

$ git config --global user.email "myemail@example.com"

Getting user name and email

To get the user name we type the following command.

$ git config user.name
Yusuf Shakeel

To get the user email we type the following command.

$ git config user.email
myemail@example.com

Setting Aliases

We use the alias to create custom shortcut for different commands.

To create an alias to check the status we can type the following command.

$ git config --global alias.s status

The above code create an alias for the git status command. (More on git status command in the later tutorials).

So, when we type the following in a repository we get the status of the repo (repository).

$ git s
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working tree clean

List all the config

To list all the configuration we use the --list option.

$ git config --list
Share

Recently Added