git config system vs global vs local

Setting up your environment while working with GIT is essential as part of user authentication to the remote code base.

The git config can be applied at 3 levels:

  • First is at system level scope:

git config --system : Resulting in the file /etc/gitconfig getting modified.

  • Second is at the Global level scope:

git config --global : The resultant configuration is present at /home/<username>/.gitconfig

  • Third is the local level scope

git config --local : The resultant configuration is present under .git/config of the current repo workspace

Lets examine the changes on various levels with the git config.

The git config at system level requires the root level permissions and provides the unique user identify to the whole system.
Lets see the demonstration as below:

[vamshi@linuxcent ~]$ git config --system user.name vamshi
error: could not lock config file /etc/gitconfig: Permission denied

We need to run the git config –system with sudo permissions.

[vamshi@linuxcent ~]$ sudo git config --system user.name vamshi
[vamshi@linuxcent ~]$ sudo git config --system user.email vamshi@linuxcent.com
[vamshi@linuxcent ~]$ cat /etc/gitconfig 
[user]
	name = vamshi
	email = vamshi@linuxcent.com

In the case of –global, The config is limited to your home directory and not on a system level and It is best advised as if you have multiple users using the system.

git config --global
[vamshi@linuxcent ~]$  git config --global user.name vamshi
[vamshi@linuxcent ~]$  git config --global user.email vamshi@linuxcent.com

To ensure the changes are made at the user level on the home directory of a user, permanently updates users’ /home/username/.gitconfig file as below:

With this the configuration at global level in the user home directory is generated and stored into the file ~/.gitconfig as shown below:

[vamshi@linuxcent ~]$ cat ~/.gitconfig 
[user]
name = vamshi
email = vamshi@linuxcent.com

The other entries can be added to the git config to accept connections from Insecure https site as shown below.

# git config --global http.sslVerify false

Resulting in modification of the global ~/.gitconfig file

[vamshi@workstation ~]$ cat ~/.gitconfig
[user]
	name = vamshi
	email = vamshi@linuxcent.com
[http]
	sslVerify = false

With these settings in place now we should be well placed and would have no issues in accessing our gitlab repos.

Adding the changes to with git config –local which only reflect the specific git repository, we will see a practical demonstration as below.

[vamshi@node02 pipeline-101]$ git config --local user.name vamshi
[vamshi@node02 pipeline-101]$ git config --local user.email vamshi@linuxcent.com
[vamshi@node02 pipeline-101]$ cat .git/config 
[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
[remote "origin"]
	url = https://gitlab.linuxcent.com/linuxcent/pipeline-101.git
	fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
	remote = origin
	merge = refs/heads/master
[user]
	name = vamshi
	email = vamshi@linuxcent.com

Could not lock config file config file exist?

This will happen, if the user home directory is not writable by the user. git config –global needs to create a “lock” file ( ~/. gitconfig. … If a user has no permission of creating this file, You must check and change permissions for the home directory.

Where is Gitconfig?

The system level configuration file lives in a gitconfig file off the system root path. $(prefix)/etc/gitconfig on unix systems. On windows this file can be found at C:\Documents and Settings\All Users\Application Data\Git\config on Windows XP, and in C:\ProgramData\Git\config on Windows Vista and newer.

How do I change .gitconfig location?

Changing . gitconfig location on Windows

  1. Move your . gitconfig from user home directory, to the directory where you want.
  2. Run command line as Administrator.
  3. Go to your user home directory.
  4. Enter mklink .gitconfig \PathForNewLocationOfConfig.gitconfig.

How do I add a config file to github?

In the working directory of your git repo, you would do the following:

  • Create a version of the config file called “config-sample. …
  • Create a symbolic link between “config. …
  • Update your .gitignore to prevent the “config.ini” from being stored. …
    (Optional, but highly recommended) Create a . …
  • Do some coding and deploy…

How do I open Gitconfig?

Open a terminal of your choice. You can also use the shortcut key Ctrl+Alt+T to open a terminal.
In your terminal type : git config –global –edit It will open your global configuration file of git in your default editor.
Change the Settings that you want.

What is Gitconfig file?

gitconfig is used to store a per-user configuration as fallback values for the . git/config file. The file /etc/gitconfig can be used to store a system-wide default configuration. The configuration variables are used by both the Git plumbing and the porcelains.

How do I change my git config file?

The global git config is simply a text file, so it can be edited with whatever text editor you choose. Open, edit global git config, save and close, and the changes will take effect the next time you issue a git command. It’s that easy.

Where is my Gitconfig file Mac?

The global Git configuration file is stored at $HOME/. gitconfig on all platforms. However, you can simply open a terminal and execute git config , which will write the appropriate changes to this file.

How do I change git config in Windows?

gitconfig on my Windows machine and found this neat trick using git. Do a: git config –global -e and then, if you are lucky, you will get a text editor loaded with your global . gitconfig file.

How do I change my git config name?

  1. In your terminal, navigate to the repo you want to make the changes in.
  2. Execute git config –list to check current username & email in your local repo.
  3. Change username & email as desired. Make it a global change or specific to the local repo: git config [–global] –replace-all user.name “Full Name” …
  4. Done!

Leave a Comment