Introduction

Version control has become an indispensable tool in modern software development. Version control systems allow you to keep track of your software at the source level. You can track changes, revert to previous stages, and branch off from the base code to create alternative versions of files and directories.
One of the most popular version control systems is git. Many projects maintain their files in a Git repository, and sites like GitHub, GitLab, and Bitbucket have made sharing and contributing to code with Git easier than ever.
In this guide, we will demonstrate how to install Git on a CentOS 7 server. We will cover how to install the software in a couple of different ways, each with their own benefits, along with how to set up Git so that you can begin collaborating right away.

Prerequisites

Before you begin with this guide, there are a few steps that need to be completed first.
You will need a CentOS 7 server installed and configured with a non-root user that has sudo privileges. If you haven’t done this yet, you can run through steps 1–4 in the CentOS 7 initial server setup guide to create this account.
Once you have your non-root user, you can use it to SSH into your CentOS server and continue with the installation of Git.

Step 1 — Installing Git

The easiest way to install Git is from CentOS’s default software repositories. This is the fastest method, but the Git version that is installed this way may be older than the newest version available. If you need the latest release, consider compiling git from source.
Use yum, CentOS’s native package manager, to search for and install the latest git package available in CentOS’s repositories:

sudo yum install git

If the command completes without error, you will have git downloaded and installed. To double-check that it is working correctly, try running Git’s built-in version check:

git --version

If that check produced a Git version number, then you can now move on to setting up Git.

Step 2 — Setting Up Git

Now that you have git installed, you will need to configure some information about yourself so that commit messages will be generated with the correct information attached. To do this, use the git config command to provide the name and email address that you would like to have embedded into your commits:

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

To confirm that these configurations were added successfully, we can see all of the configuration items that have been set by typing:

git config --list

user.name=Your Name
user.email=you@example.com

This configuration will save you the trouble of seeing an error message and having to revise commits after you submit them.

Conclusion

You should now have git installed and ready to use on your system. To learn more about how to use Git, check out these more in-depth articles:

How To Use Git Effectively
How To Use Git Branches