First Time Git Setup | Git Config Global


GIT

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 https://launchpad.net/~git-core/+archive/candidate .
 More info: https://launchpad.net/~git-core/+archive/ubuntu/ppa
Press [ENTER] to continue or Ctrl-c to cancel adding it.

Hit:1 http://in.archive.ubuntu.com/ubuntu bionic InRelease
Hit:2 http://in.archive.ubuntu.com/ubuntu bionic-updates InRelease                                    
Hit:3 http://in.archive.ubuntu.com/ubuntu bionic-backports InRelease                                                                                  
Get:4 http://ppa.launchpad.net/git-core/ppa/ubuntu bionic InRelease [20.8 kB]                                                                         
Get:5 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]          
Get:6 http://ppa.launchpad.net/git-core/ppa/ubuntu bionic/main i386 Packages [3,020 B]           
Get:7 http://ppa.launchpad.net/git-core/ppa/ubuntu bionic/main amd64 Packages [3,032 B]
Get:8 http://ppa.launchpad.net/git-core/ppa/ubuntu 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 user.name "Deepak Prasad"

 

Set Email Address

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

root@ubuntu:~# git config --global user.email "admin@golinuxcloud.com"

 

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.

NOTE:
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
user.name=Deepak Prasad
user.email=admin@golinuxcloud.com
core.editor=vim

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

root@ubuntu:~# cat .gitconfig 
[user]
	name = Deepak Prasad
	email = admin@golinuxcloud.com
[core]
	editor = vim

You can also get the individual configuration value using:

root@ubuntu:~# git config user.name
Deepak Prasad

root@ubuntu:~# git config user.email
admin@golinuxcloud.com

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

 

Summary

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

Deepak Prasad

Deepak Prasad

Deepak Prasad is the founder of GoLinuxCloud, bringing over a decade of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, Networking, and Security. His extensive experience spans development, DevOps, networking, and security, ensuring robust and efficient solutions for diverse projects.

Certifications and Credentials:

  • Certified Kubernetes Application Developer (CKAD)
  • Go Developer Certification
  • Linux Foundation Certified System Administrator (LFCS)
  • Certified Ethical Hacker (CEH)
  • Python Institute PCAP (Certified Associate in Python Programming)
You can connect with him on his LinkedIn profile and join his Facebook and LinkedIn page.

Can't find what you're searching for? Let us assist you.

Enter your query below, and we'll provide instant results tailored to your needs.

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 send mail to admin@golinuxcloud.com

Thank You for your support!!

Leave a Comment