Skip to content

Instantly share code, notes, and snippets.

@gsoldateli
Created October 3, 2017 13:24
Show Gist options
  • Select an option

  • Save gsoldateli/0b65acbb947b225f790caa4874b097e4 to your computer and use it in GitHub Desktop.

Select an option

Save gsoldateli/0b65acbb947b225f790caa4874b097e4 to your computer and use it in GitHub Desktop.
A short introduction on how to use git config command.

Discuss the purpose and importance of the .gitconfig, located in your $HOME directory.

.gitconfig and your development environment.

.gitconfig file in your $HOME directory is where you place all the git configurations for your OS user.

Why should you use .gitconfig?

Using .gitconfig enables you to configure your git to meet your preferences of colors/workflow/personal data.

Let's see some examples of what you're capable of using git config command.

First things first.

git config is a command that writes inside your .gitconfig files, you will want use this command to avoid mistyping errors inside the .gitconfig file.

When you have a fresh git installation in your machine, your .gitconfig file will probably be empty.

cat ~/.gitconfig 

#Output: (EMPTY FILE)

Setting your user name and email.

Now, let's add your user email and name to your .gitconfig file.

# git config theorical basic syntax
# git config <--directives-you-want-to-use> <option.suboption> <value>

git config --global user.email  "your@mail.com"
git config --global user.name  "Your Name"

PS:. --global directive will be explained in the sections below with more detail, for the moment you need to understand that --global relates to the git configuration of your OS user.

Look what git config did to your gitconfig file:

cat ~/.gitconfig 

#Output:
#[user]
#     email = your@mail.com
#     name = Your Name

Now git knows the basic information needed when logging your actions within your repositories.

Setting your prefered text editor to vim

Sometimes when using git, it opens an text editor inside the terminal.

If the text editor is not of your preference you can say to git which one you want to use with the option core.editor

# Sets vim as my OS user prefered terminal text editor.
git config --global core.editor vim

There is a better way to debug gitconfig files instead using cat ?

If you want to see what configurations are in place without having to read the entire configuration file you may use:

## You may use git config <option> without assigning value
git config user.name #Let's say you want to know your user.name

#OUTPUT:
# Your Name

<option> accepts TAB AUTOCOMPLETE. This is great when you don't know what options are availabe to you!

git config user.<press TAB twice>

#OUTPUT:
# user.email        user.name         user.signingkey 

A brief explanation on WHY to use --global.

The thing is... there are more .gitconfig files around your OS than the file located in your home folder ~/.gitconfig.

Each of these files corresponds to a hierarquic level of configuration.

If you write

Level Directive Location (Unix OS) Importance
Entire OS --system /etc/gitconfig Using git config --system you'll be setting a configuration to the whole OS. all OS users will be affected.
Your OS User --global ~/.gitconfig Using git config --global the configuration scope will be only for the current logged user. Everything you configure here will override the --system conf.
Local git repository --local (Or none, this is default) Using git config --global the configuration scope will be only for the current repository. Everything you configure here will override the --system and --global conf.

I really hope this content can be of help showing how important is to configure your git avoiding misconceptions that may make you lose precious time of life.

Guilherme Soldateli

08/24/2017

Career Path 3: Modern Frontend Developer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment