Configure Git
Previously, we have discussed about how to install Git on various platforms. After you install Git, the next step is to configure it before it us used for the first time.
To configure Git, we use the command git config
. This command can accept parameters and arguements and can set and obtain the configuration variables.
There are 3 different configuration levels in Git. They are:
System (
--system
) - This configuration level covers an entire user, machine and all the repos in it. Changes made in this level affects the entire system and all repos in the system is affected. Editing the system level configuration is often discouraged because of this.Global (
--global
) - This configuration level affects the User level. This means that configuration changes will apply to all the files of the user who is currently operating the system.Repository (
--local
) - This configuration level only affects a specific repo (repository).
The configuration variables can be located at various places depending on your platform.
In GNU/Linux systems they are generally located in 3 different places:
/etc/gitconfig
- stores System Level configurations.~/.gitconfig
- stores Global configurations.~/<RepoFolder>/.git/config
- stores Repository Level configurations.
In Windows system, they are located in:
C:\Documents\Git\etc\gitconfig
- stores System Level configurations.C:\Document and Settings\<UserName>\.gitconfig
orC:\Users\<UserName>\.gitconfig
- stores Global configurations.C:\<RepoFolder>\.git\config
- stores Repository Level configurations.
In Mac, config files are located similar to Linux:
/usr/local/git/etc/gitconfig
- stores System Level configurations.~/.gitconfig
- stores Global configurations.~/<RepoFolder>/.git/config
- stores Repository Level configurations.
Configure Username and Email
After installing, the first step should be to set your username and email correctly.
To set up Git username and email use the following commands:
1
2
git config --global user.name <your name>
git config --global user.email <user@email.com>
Please replace
<your name>
and<user@email.com>
with your own name and email.
Configure Default Text Editor
By default, Git uses your default text editor through one of the shell environment variables VISUAL
or EDITOR
. Otherwise it falls back to the vi
editor. However, if you wish to set one of your favorite editors as default, you need to use the core.editor
setting, e.g.
1
git config --global core.editor editor-name
- To setup Sublime Text as default editor in Windows:
1
git config --global core.editor "'C:/Program Files/Sublime Text 2/sublime_text.exe' -n -w"
or in Mac/Linux:
1
git config --global core.editor "'/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl' -n -w"
- To setup VSCode as default editor:
1
git config --global core.editor "code --wait"
- To setup Atom as default editor:
1
git config --global core.editor "atom --wait"
List Configurations
Once the basic configuration is in place, use the following command to check if the configurations have updated:
1
git config --list
The output of the above command should echo the following information:
1
2
3
user.name=exampleuser
user.email=user@email.com
core.editor=editor-name
These were the basic configurations you will need to start working with Git. However, there are several other configuration parameters that you can modify as per your requirements. You can find a full and detailed list of Git Configuration here.
That’s all for now, in the next part we will discuss how to use Git with a Local Repository.
Comments powered by Disqus.