How To Install Git on CentOS 7

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 sudoprivileges.

Once you have your non-root user, you can use it to SSH into your CentOS server and continue with the installation of Git.

Install Git

The two most common ways to install Git will be described in this section. Each option has their own advantages and disadvantages, and the choice you make will depend on your own needs. For example, users who want to maintain updates to the Git software will likely want to use yum to install Git, while users who need features presented by a specific version of Git will want to build that version from source.

1. Install Git with Yum

The easiest way to install Git and have it ready to use is to use CentOS’s default 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 (the steps for this method can be found further down this tutorial).

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, found further down this article.

2. Install Git on CentOS With another Repo

To install latest Git in CentOS you will need to enable GIT repository in CentOS. First, create a new file inside /etc/yum.repos.d/ directory using following command. Then copy the lines given below the command.

sudo nano /etc/yum.repos.d/wandisco-git.repo

Copy below lines inside above created file.

[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

Now save and exit the editory typing CTRL+X then typing ‘Y’.

Next, Import GPG key for added repository key typing below command.

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

Now install Git by typing following command:

sudo yum install git

Confirm the installation and check the version executing the following command

git --version

The output should be:

git version 2.18.0

3. Setting Up Git

The first thing that you might want to do after the installation is to configure your name and email address in Git so the changes you commit contain the correct information. You can do that by using the following commands:

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

List configuration settings

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

git config --list

The output should be similar to the following one:

# git config --list
user.name=Your Name
user.email=user@domain.com

Git command line option and help

For more information and command line options you can use the --help flag.

git --help

It will list the most commonly used Git commands.

   add        Add file contents to the index
   bisect     Find by binary search the change that introduced a bug
   branch     List, create, or delete branches
   checkout   Checkout a branch or paths to the working tree
   clone      Clone a repository into a new directory
   commit     Record changes to the repository
   diff       Show changes between commits, commit and working tree, etc
   fetch      Download objects and refs from another repository
   grep       Print lines matching a pattern
   init       Create an empty Git repository or reinitialize an existing one
   log        Show commit logs
   merge      Join two or more development histories together
   mv         Move or rename a file, a directory, or a symlink
   pull       Fetch from and merge with another repository or a local branch
   push       Update remote refs along with associated objects
   rebase     Forward-port local commits to the updated upstream head
   reset      Reset current HEAD to the specified state
   rm         Remove files from the working tree and from the index
   show       Show various types of objects
   status     Show the working tree status
   tag        Create, list, delete or verify a tag object signed with GPG

You can also refer to the Git documentation which is available here.

Be the first to comment

Leave a Reply

Your email address will not be published.


*