Git is a distributed version control system used by most software teams today. It allows you to track your code changes, restore the previous staging area, create branches, and collaborate with your development colleagues.
Git was originally developed by Linus Torvalds, the creator of the Linux kernel.
This guide explains how to install Git on CentOS 8.
The easiest and most recommended way to install Git is to use the yum
package manager to install it.
If you want to compile and install the latest stable Git from the source code, slide to the back to see " Installing Git from the Source " in the guide
The Git package is included in the default source repository of CentOS.
As root or another user with sudo privileges, install Git on your CentOS system:
sudo yum install git
Print out the Git version number by typing the following command:
git --version
At the time of writing this article, the currently available version of Git in the CentOS 8 source repository is 2.18.1
.
git version 2.18.1
that's it. You have installed Git and are ready to use it.
Compiling Git from source code allows you to install the latest Git version and customize some build options. In any case, you will not be able to maintain your Git installation process through the yum
package manager.
Start to install some necessary dependency packages to build Git on CentOS:
sudo yum groupinstall "Development Tools"
sudo yum install curl-devel expat-devel gettext-devel openssl-devel perl-CPAN perl-devel zlib-devel
Once the installation is complete, open your browser, browse: Git project's mirror on GitHub, and copy the latest release link, ending with .tar.gz
.
Currently, the latest stable version of Git is 2.23.0
.
We download the Git source code to the /usr/src
directory, usually we put the code here. Switch to this directory:
cd /usr/src/
Use the previously copied link to download the tar.gz file just now, similar to git.tar.gz
sudo wget https://github.com/git/git/archive/v2.23.0.tar.gz -O git.tar.gz
Next, unzip and enter the following command to switch to the git source code directory:
sudo tar -xf git.tar.gz
cd git-*
Run the following two commands to compile and install Git on your CentOS system
sudo make prefix=/usr/local all
sudo make prefix=/usr/local install
Enter git --version
to verify your installation:
git --version
git version 2.23.0
Later, if you want to upgrade to a newer version, download the compressed package and repeat the same build process.
Now that you have installed Git on your CentOS machine, it is time to set your personal information. The following command will set your submission name and email address:
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
To confirm that your information is correct, enter:
git config --list
user.name=Your Name
[email protected]
This configuration information is stored in the ~/.gitconfig
file:
[ user]
name = Your Name
email = [email protected]
If you want to add some global Git configuration information, you can use the git config
command or directly edit the ~/.gitconfig
file.
Installing Git on CentOS 8 is very simple, just a single yum
command can do it. If you want to use the latest version of Git, you need to compile it from source.
If you are new to Git, I suggest you read "Pro Git Chinese Version", it is an excellent book on learning how to use Git.
Recommended Posts