Git Configuration Settings

Git Configuration Settings

Git configuration

Configuring our git on our local machines and virtual machines (VM) is important to tell git about the user.

It is very advisable to always configure our git before we start using it locally. This helps prevent conflicts and request of passwords when committing and pushing our works to github.

The major advantage is that anytime we make a future commit, git will remember the configuration.

We can do this in two ways :

  1. setting a global git username and email.
  2. setting git username and email for a single repository.

Setting a global git username and email.

This configuration type will apply to commits you make to all repositories in your local machine without any repository-specific values.

To set your global repositories name and email address :

$ git config --global user.name "your name"

$ git config --global user.email "youremail@general.com"

The --global option specifies that your configuration settings will be applied to all repositories.

After that, we can confirm if our configuration was saved and recognised by git by using the --list option :

$ git config --list
user.name = your name
user.email = youremail@general.com

Setting git username and email for a single repository

In some cases, we may consider using our configuration for a single repository.

To achieve this, we run the git config without the --global option :

$ git config user.name "your name"

$ git config user.email "youremail@general.com"

Similarly, to confirm our configuration, we run the git config --list

We should be aware that :

  1. global settings configuration file are saved in ~/.gitconfig
  2. specific settings configuration are saved in .git/config