Git Config Recommended Settings

“Git config” is not only a concept but a command. When first starting out with Git, a few configurations must be made right away. You can provide these configurations by running a few commands, but as you continue to use Git for more and more projects, you may have need more advanced configurations. In the latter case, you may find it helpful to create a configuration file that you can update and carry with you to other workstations — should the need arise.

If you don’t need cPanel, don't pay for it. Only pay for what you need with our scalable Cloud VPS Hosting.

check markCentOS, Debian, or Ubuntu check markNo Bloatware check markSSH and Root Access

Git Config Commands and Configuration

At the very least, in order to do a proper commit, Git requires that you submit your name and email address. You don’t have to use your real name or real email address, but these details are necessary to personalize your commits. A Git project would be chaotic if there was no way to tell who committed what and when.

These commands provide the personal data necessary to get started. For your name:

git config --global user.name "Joe Example"

And email:

git config --global user.email [email protected]

These commands will configure your Git installation at the system level. But there are other levels for which you might to provide different configurations. More on those locations and files below.

Using Configuration Files

Using configuration files for Git can provide a lot of value for you. First of all, you can more easily tweak and customize how you use Git. And being able to find these settings in a convenient location can also help you backup and share those settings with other users or across workstations.

Git will search three locations for configuration settings. Each successive level overwrites values from the previous level. For example, values set in the project (.git/config) will overwrite those set for the system (/etc/gitconfig).

Learning about these different levels as locations in your file system will help you make sure you provide the right configuration in the right place.

System level
First, Git will look in the /etc/gitconfig file to identify any system-wide configurations. You can pass configurations to this file by adding the --system option to the default git config command.
Home level
The home directory file ~/.gitconfig contains the user level configurations that will only apply to the user.
Project level
In the .git/config file, values are saved in the project working directory or repository and will thus affect the project.

Depending on how, when, and where you plan on updating these files, it’s up to you where you want to make these changes. For the sake of simplicity I would recommend first setting up the home directory file, .gitconfig, because your settings will only apply to your user account. If you plan on adding other users to your system, and you wish to apply some configurations globally or systemically then you would consider updating the other files as needed.

Below you will find some recommended configurations for your local Git operations. These types of configurations are ideal additions to your local ~/.gitconfig file that you will store in your home directory.

Name and Email Configuration

Of course, first and foremost, Git requires that you provide a name and email with which to sign commits from your account. Every commit you make in Git must have a name and email attached, as a way of attributing work to the right person. You can add these to your local Git config likewise:

[user]
name = Joe Example
email = [email protected]

If you do not have these values covered you will see an error when first trying to create a commit.

Git Aliases

Adding aliases to your Git config speeds up your command input.

[alias]
st = status
logg = log --graph --decorate --oneline --all
cm = commit
df = diff
dfs = diff --staged

To take an example from above, in order to run the git status command you can simply type git st and get the same result. Notice that you can provide even long strings of options and combinations and nest them all in one truncated input line.

Remote Repositories

You can also add remote repositories right from the config file. In the example below, you have a remote repository called “origin,” to and from which you can push and pull.

[remote "origin"]
url = [email protected]:/var/lib/git/production.git
fetch = +refs/heads/*:refs/remotes/origin/*

Text Editor

When you initiate a commit with the git commit command, you are prompted to enter your commit message in a text editor. Here, you can specify which text editor you would prefer to use. In the example below, the emacs text editor is selected, but you could instead use nano, gedit, vim, or whatever editor you use regularly.

[core]
editor = emacs

Now you know what settings you will need for a solid Git configuration. Where will your Git journey take you next?

CM
Christopher Maiorana Content Writer II

Christopher Maiorana joined the InMotion community team in 2015 and regularly dispenses tips and tricks in the Support Center, Community Q&A, and the InMotion Hosting Blog.

More Articles by Christopher

Was this article helpful? Join the conversation!