.gitconfig file in your $HOME directory is where you place all the git configurations for your OS user.
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)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 NameNow git knows the basic information needed when logging your actions within your repositories.
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 vimIf 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 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