First Time Git Setup | Git Config Global

Now that you are familiar with the basic concepts of Git, now we are ready to setup git environment. In this tutorial we will install and configure git.


Install Git

Git’s official website provides detailed instructions on installing Git on your local machine, depending on your operating system.


The easiest way to install Git is through a package manager based on your operating system. Package managers usually have older but more reliable versions of Git. If you’re using Linux, you can install Git through the terminal using a package manager. For the popular Linux distro Ubuntu, Git can be installed using apt-get.

First we will add a new repository to install the latest stable Git version:

root@ubuntu:~# add-apt-repository ppa:git-core/ppa
 The most current stable version of Git for Ubuntu.

For release candidates, go to .
 More info:
Press [ENTER] to continue or Ctrl-c to cancel adding it.

Hit:1 bionic InRelease
Hit:2 bionic-updates InRelease                                    
Hit:3 bionic-backports InRelease                                                                                  
Get:4 bionic InRelease [20.8 kB]                                                                         
Get:5 bionic-security InRelease [88.7 kB]          
Get:6 bionic/main i386 Packages [3,020 B]           
Get:7 bionic/main amd64 Packages [3,032 B]
Get:8 bionic/main Translation-en [2,252 B]
Fetched 118 kB in 2s (60.1 kB/s)                    
Reading package lists... Done

Next install git package:

root@ubuntu:~# apt-get install git


Check git version

Once you have Git installed, you can check the version of the git installed:

root@ubuntu:~# git --version
git version 2.32.0


Git configuration files

Git configuration files are all simple text files in the style of .ini files. The configuration files are used to store preference and settings used by multiple git commands. Like other tools, git supports a hierarchy of configuration files.


Hierarchy of git configuration files

Following represents the git configuration files hierarchy in decreasing precedence:

  • .git/config: Repository-specific configuration settings manipulated with the --file option or by default. You can also write to this file with the --local option. These settings have the highest precedence.
  • ~/.gitconfig: User-specific configuration settings manipulated with the --global option.
  • /etc/gitconfig: System-wide configuration settings manipulated with the --system option if you have proper Unix file write permissions on it. These settings have the lowest precedence. Depending on your actual installation, the system settings file might be somewhere else (perhaps in /usr/local/etc gitconfig), or may be entirely absent.


Setup git environment

Set Username

Assign a username which will be used for each commit globally:

root@ubuntu:~# git config --global "Deepak Prasad"


Set Email Address

Assign an email address which will be used for each commit globally:

root@ubuntu:~# git config --global ""


Set Default Editor

You can set the editor to the editor of your choice either by changing the $EDITOR environment variable or with the core.editor configuration target,

root@ubuntu:~# git config --global core.editor vim


Set default branch name

Starting in Git 2.28, git init will look to the value of init.defaultBranch when creating the first branch in a new repository. If that value is unset, init.defaultBranch defaults to master.

To set main as the default branch name do:

$ git config --global init.defaultBranch main

We plan to use master as default branch so we will leave this command.


There are some more set of important configuration parameters which should be configured, I will share them in upcoming articles once we have initialized our repository.


List configuration values

You can now list the applied configuration to your git server:

root@ubuntu:~# git config --list Prasad

You can also check the same in ~/.gitconfig file:

root@ubuntu:~# cat .gitconfig 
	name = Deepak Prasad
	email =
	editor = vim

You can also get the individual configuration value using:

root@ubuntu:~# git config
Deepak Prasad

root@ubuntu:~# git config

root@ubuntu:~# git config core.editor



In this git tutorial we covered the steps to install and do a basic configuration of git environment. Although this is a very basic configuration, we will continue with the configuration in next articles once we setup our repository.


Further Readings

First-Time Git Setup – Git
Git Configuration – Git

Didn't find what you were looking for? Perform a quick search across GoLinuxCloud

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can either use the comments section or contact me form.

Thank You for your support!!

Leave a Comment