Make sure Git is installed, you can check Git version use git --version command in your terminal.

We will configure Git using git config command. These commands set values on a global or local project level and correspond to .gitconfig text file.

Configuration level

Configuration level is specified following git config with a --double-dash as an option. There are three configuration levels:

  • Global level (global)
  • Local level (local)
  • System level (system)

By default, git config will write to a local level if no configuration option is passed.

Local level

Local level configuration is applied to the context repository. Configure to a local level we type :

git config --local

Local configuration values are stored in a file in the repo’s .git directory (hidden): .git/config

Global level

Global level configuration is user-specific, applies to all repositories of the current OS user. To configure at a global level we do:

git config --global

The global configuration values are stored in a user’s home directory ~/.gitconfig if you are using a Unix like system.

System level

System level configuration is applied to all users of an OS. It covers ever user’s repos. Use the following command to configure at system level:

git config --system

The system level configuration file resides at the system root path $(prefix)/etc/gitconfig on Unix systems.

User configuration

Git commit uses user information, to set user name and email address you use git config command:

git config --global user.name "John Doe"
git config --global user.email johndoe@example.com

Your editor

You can configure the default text editor that will be used when Git needs you to type in a message. If not configured, Git uses system default editor. This is an example of Vim as the editor:

git config --global core.editor "vim"

Check configuration settings

If you want to check your configuration settings, you can use the git config --list command to list all the settings Git can find at that point:

git config --list
user.name=John Doe
user.email=johndoe@example.com
color.status=auto
color.branch=auto
...

You can also check what Git thinks a specific key’s value is by typing git config <key>:

git config user.name
John Doe

Type :q to quit view mode

Default branch name

By default Git will create a branch called mater when you create a new repository with git init. But you can set a different name for the initial branch.

git config --global init.defaultBranch <branch_name>

Back to parent page: Git

DevOpsVCSGit