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.
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.
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.
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
Outputuser.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.
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:
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
This article is missing a key ingredient: cURL.
This enables the HTTPS remote helper when cloning repositories.
This is how you can enable the HTTPS remote helper:
sudo yum install curl-devel
./configure --prefix=/usr --with-curl
make
as normalNow you can
git clone https://...
. Enjoy!Instructions like these are hugely helpful. Thanks.
I don’t know what is best, but I used
./configure --prefix=/usr
to overwrite the older yum installed version.
how to install in docker in centos-9server,
my email== rritsoftwaresolutions@gmail.com
india , + 91 9505782251, watsup
WHat about uninstalling it? There’s no instructions on that…
Ironically enough, using the group install “Development Tools” actually installs the git package from yum, which is what I’m trying to avoid. To that end, I instead installed all the build prerequisites specifically, as described on https://git-scm.com/book/en/v2/Getting-Started-Installing-Git The only difference is that perl wasn’t specifically mentioned there.
Here’s an ansible playbook to do the above process…
name: configure test01 hosts: test01 vars: git_version: “2.14.2” # https://github.com/git/git/releases git_user_name: “{{ ansible_hostname }}” git_user_email: “{{ ansible_hostname }}@company.com” tasks:
https://www.digitalocean.com/community/tutorials/how-to-install-git-on-centos-7
https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
name: install build prerequisites become: yes yum: name: “{{ item }}” state: latest with_items:
name: download git {{ git_version }} get_url: url: https://github.com/git/git/archive/v{{ git_version }}.tar.gz dest: /tmp/git.tar.gz when: git_versions_match.rc != 0
name: extract git.tar.gz unarchive: src: /tmp/git.tar.gz dest: /tmp remote_src: yes when: git_versions_match.rc != 0
name: make configure make: chdir: /tmp/git-{{ git_version }} target: configure when: git_versions_match.rc != 0
name: configure command: ./configure --prefix=/usr/local args: chdir: /tmp/git-{{ git_version }} when: git_versions_match.rc != 0
name: make install remote_user: root make: chdir: /tmp/git-{{ git_version }} target: install when: git_versions_match.rc != 0
name: git config user name git_config: name: user.name value: “{{ git_user_name }}” scope: global
name: git config user email git_config: name: user.email value: “{{ git_user_email }}” scope: global
name: git config rebase on pull git_config: name: pull.rebase value: true scope: global
name: git config branch.autosetuprebase always git_config: name: branch.autosetuprebase value: always scope: global
After installing git from source following this tutorial, I can’t run git command elsewhere other than /usr/local/bin. I need to create a symbol file for it. ln -s /usr/local/bin/git /usr/bin/git
A very useful tutorial, thanks!