Git Config Files

Git distributed version control software runs on Windows, Mac, and Linux.  It is the fastest open source version control software, and is used to keep historical track of  some very large projects, like the Linux operating system itself, for example.

Because of the breadth of the coverage across multiple operating systems, using various tools, and multiple distributed branches and projects, git needs to keep track of different paths to other repositories, user settings,  and preferences.  It does this in config files.

Git uses more than one config file, and knowing where your information resides when you have a problem, and want to see what is configured can be a challenge.

When you first start a new repository with the git init command, git will set up a hidden .git folder in the same directory that you were in when you ran git init.  This is your new repository with the tracking folders and files git will use to track every change you make in the folder or sub folders below it.  One of the files in the .git folder is the config file.   This is a plain text file that can be edited with a text editor, although I do not recommend you do that initially.

The .git/config file is present with every repository and is used to store the individual configuration for that repository.  It is also where you store information about any repositories that you have cloned or copied from somewhere else and want to set up a two way communication.  Here's a .git/config file with a connection to a remote repository.

The .git/config file

When you set up a clone of a remote repository, and you cannot establish a connection, it is probably because the url in the .git/config file is not correct.  Here's where you can edit the url which is sometimes easier then entering it from the command line.  This is also where you give your remote location a name, in this case "origin."

You can add variables to the local config file from the command line by using a --file flag like this: git config --file "john doe"

The next configuration file is located in your $HOME directory.  If your not sure where that is go to cd $HOME and you'll find it.  The $HOME directory contains your .gitconfig file.  It's used as a backup in case you forget to config the local repository .git/config file, and if you have more than one repository it is used to synchronize your config across all your repositories.  This is also where you tell git of any third party software applications you'd like to run, like a merge tool, in this case I'm using, diffmerge.

The .gitconfig file

You can add to your .gitconfig file with the --global flag like this: git config --global "john doe"

One of the first things you do when you start a new repository with the git init command is to tell git your user name and email address so it can track your changes for you.  This is done with a "git  config --global 'Frank Dune' " and "git config --global "" commands.

The next config file is your system config file, gitconfig.
This contains your system configuration settings used in running the git application.  You can add to your etc/gitconfig file with the --system flag like this: git config --system core.autocrlf true.

The etc/gitconfig file

You'll notice all three config files have a different name:
.git/config, .gitconfig, and etc/gitconfig.  Git uses these in order when looking for parameters.  First the local repository .git/config, then the global repository .gitconfig, and then the system repository etc/gitconfig.

These are all text files and you can open each of these in a text editor and edit it directly.  Be careful about Linux and Windows line feeds.  To be safe edit the config files in Git bash with a Linux editor like vi.  Editing the file comes in handy when you need to get paths or parameters in a very specific syntax.

The only caution here is if you change your $HOME directory, make sure you copy your .gitconfig to your new home since programs like your favorite diffmerge tools are configured here.

This entry was posted in Git - Version Control and tagged . Bookmark the permalink.