Menu ↓

Git Configuration Level

I've been working with Git for five years and only realized how useful Git configuration level is

When you start with Git, most people will recommend you set the username and email on a global level.

$ git config --global "John Doe"
$ git config --global ""

Well, this is not wrong. Because you only need to set it up once and just forget about it.

But, when you start to contribute to multiple accounts, it will become a problem. For example, you started contributing to an open source organization that provides you with different accounts. vs

Now, let's back to the Git configuration level. Git allowed us to define a configuration variables that control all aspects of how Git looks and operates. These variables can be stored in three different places or three different levels:

  • project: Project configs level are only available for the current project and stored in .git/config in the project's drectory.
  • global: Global configs level are only available for all projects for the current user and stored in $HOME/.gitconfig.
  • system: System configs level are available for all the users/projects and stored in /etc/gitconfig.

Create a project specific config, you have to execute this under the project's directory:

$ git config "John Doe"

Create a global config:

$ git config --global "John Doe"

Create a system config:

$ git config --system "John Doe"

And as you may guess, project overrides global and global overrides system.

Project configs are local to just one particular copy/clone of this particular repo, and need to be reapplied if the repo is re-cloned clean from the remote. It changes a local file that is not sent to the remote with a commit/push

Now, you know about the Git configuration level. But, what next?

In my case, I will set up a Git global configuration for most projects in my workspaces. Then, for the minority, I will set up the Git configuration on the project level.

Menu Navigation