Setting Up Your Git Environment: A Step-by-Step Guide
Get started with Git by following these easy steps to install the Git client on Ubuntu or CentOS Linux. Learn how to configure your Git environment and make it ready for version control.
Git - Environment Setup
Before you can use Git, you need to install it and make some basic configuration changes. Below are the steps to install the Git client on Ubuntu and CentOS Linux.
Installation of Git Client
If you're using a Debian-based GNU/Linux distribution, you can install Git using the apt-get
command:
Syntax
[ubuntu ~]$ sudo apt-get install git-core
[sudo] password for ubuntu:
[ubuntu ~]$ git --version
git version 2.25.1
Output
git version 2.25.1
For RPM-based GNU/Linux distributions like CentOS, use the yum
command:
Syntax
[CentOS ~]$ su -
Password:
[CentOS ~]# yum -y install git-core
[CentOS ~]# git --version
git version 2.18.4
Output
git version 2.18.4
Customize Git Environment
Git provides the git config
tool, which allows you to set various configuration variables. These configurations are stored in different locations:
- Global Configurations: Stored in the
.gitconfig
file in your home directory. Use the--global
option to set them. - System-wide Configurations: Stored in the
/etc/gitconfig
file, which requires root access. Use the--system
option to set them.
Setting Username and Email
This information is used by Git for each commit you make:
Syntax
[jerry@CentOS project]$ git config --global user.name "John Doe"
[jerry@CentOS project]$ git config --global user.email "john@example.com"
Output
Configurations updated successfully.
Avoid Merge Commits While Pulling
By default, when you pull changes from a remote repository, Git creates merge commits if the changes are divergent. To avoid this, you can set Git to always rebase instead:
Syntax
[jerry@CentOS project]$ git config --global branch.autosetuprebase always
Output
Autosetup for rebase is enabled.
Enable Color Highlighting
To enable color highlighting for Git commands in the console, you can use the following configuration:
Syntax
[jerry@CentOS project]$ git config --global color.ui true
[jerry@CentOS project]$ git config --global color.status auto
[jerry@CentOS project]$ git config --global color.branch auto
Output
Color highlighting is enabled.
Set Default Editor
Git uses the system default editor, which is taken from the VISUAL
or EDITOR
environment variable. You can configure a different editor by using:
Syntax
[jerry@CentOS project]$ git config --global core.editor vim
Output
Default editor set to vim.
Set Default Merge Tool
Git does not provide a default merge tool for resolving conflicts. You can set a merge tool like vimdiff
with the following command:
Syntax
[jerry@CentOS project]$ git config --global merge.tool vimdiff
Output
Merge tool set to vimdiff.
Listing Git Settings
To verify your Git configuration settings for the local repository, use the git config --list
command:
Syntax
[jerry@CentOS ~]$ git config --list
Output
user.name=John Doe
user.email=john@example.com
branch.autosetuprebase=always
color.ui=true
color.status=auto
color.branch=auto
core.editor=vim
merge.tool=vimdiff