Git Config Recommended Settings

Git Config Recommended Settings
No matter if you’re a developer, system administrator, or simply a fan of SSH and command line, InMotion’s Cloud VPS plans provide a fast, scalable environment that is budget-friendly.

“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.

Git Config Commands and Configurations

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. Git would be chaotic if there was no way to tell who committed what.

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]

Git will search three locations for config 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).

System level
First, Git will look into 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 user level configurations that will only apply to the user.
Project level
In the .git/config file, these values are saved in the project working directory or repository.

Depending on how, when, and where you plan on updating this file, it’s up to you where you want to make these changes. For the sake of simplicity I would recommend 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.

Name and Email

Of course, first and foremost, Git requires that you provide a name and email with which to sign commits from your account. You can add these to your local Git config likewise:

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

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 put nano, gedit, vim, or whatever editor you use regularly.

[core]
       editor = emacs

Check out other Git-related articles in the Support Center:

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? Let us know!