How to Install Git on CentOS 7

Install Git on CentOS 7

In this article, we will have explained the necessary steps to install and configure Git on CentOS 7. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

Git is a distributed version control system, which you can use to track the code changes (versions) while developing software. Git offers features such as reverting to a previous stage, multiple workflows, local branching, and many others. This makes Git one of the best version control systems and that is why it is used by many software developers.

Install Git on CentOS

Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.

sudo yum install epel-release
sudo yum update

Step 2. Install Git on CentOS 7.

First, enable the Wandisco GIT repository:

nano /etc/yum.repos.d/wandisco-git.repo
[wandisco-git]
name=Wandisco GIT Repository
baseurl=http://opensource.wandisco.com/centos/7/git/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://opensource.wandisco.com/RPM-GPG-KEY-WANdisco

Import the repository GPG keys:

sudo rpm --import http://opensource.wandisco.com/RPM-GPG-KEY-WANdisco

Now install Git by typing following command:

sudo yum install git

To verify that Git is successfully installed you can use the following command:

# git --version
git version 2.18.0

Step 3. Setting Up Git.

Now that you have Git installed it is a good idea to set up your personal information that will be used when you commit changes to your code:

git config --global user.name "meilanamaria"
git config --global user.email "meilanamaria@yourdomain.com"

You can also change above configuration by editing .gitconfig file. To edit gitconfig file type:

nano ~/.gitconfig

To verify that you entered the correct information you can use the command below:

git config --list

Congratulation, you have learned how to install and configure Git on CentOS 7. If you have any question, please leave a comment below.