Hamsa K
Editor
7 min read | 3 years ago

How to Install Git 2 23 on Centos 7

How to install git 2.23 on Centos 7

Git is the most popular version control system that’s being used by hundreds of thousands of projects. Git allows you to keep track of your code changes, revert to previous stages, work simultaneously on multiple branches.It is designed to handle a small to very large projects with speed and efficiency.
Also Read -> How to Install Nodejs on Centos 7

Method 1:

This is the easy way to install through yum.For this first we need to enable IUS repository or Wandisco GIT Repository

vi /etc/yum.repos.d/wandisco-git.repo

Add below content to above 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

save the file. then Import the repository GPG keys with below command

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

Once the repository is added, to install the latest version of Git run the following command

yum install git

Now you can check git version using the command 'git --version'

Also Read -> How to Install PgAdmin4 in CentOS 7

Method 2:

Compiling from source code

If you want to compile latest version of git from source code then follow below steps.

prerequisites:

yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker

After installing above packages download lastest version of git from this url

cd /usr/src
wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.23.0.tar.gz
tar -xvzf git-2.23.0.tar.gz

After downloading and extracting Git source code, Use the following command to compile the source code.

cd git-2.23.0/
./configure --prefix=/usr/local/git
make
make install

Also Read -> How to Install Docker on Centos 7

Setup environment

Now you just need to set binary in the system environment.

echo "export PATH=/usr/local/git/bin:$PATH" >> /etc/bashrc
source /etc/bashrc
git --version

sample output:

git version 2.23.0

Configuring 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 "Your Name"
git config --global user.email "youremail@yourdomain.com"
git config --list

sample output:

user.name=Your Name
user.email=youremail@yourdomain.com

That's it.Git has been successfully installed on your system.

Also Read -> How to Install Webmin on Centos 7

Basic commands

To initiate a new git repository,use following command.

git init

To check status of files in index versus working directory for your git repository.

git status

Add file to git repository

create one test file and add that file to the index of the git repo.

echo "this is my first file" >> test.txt
git add test.txt

commit the file

git commit -m 'my first commit'

we were working with local repository only. so that others cannot use changes which are made by us as they are local.We will publish local changes to remote repository using push command.

Then, push changes to the repository.

 git push

This will push the changes into the master branch.

To check the commit log

git log

git fetches the changes of the remote repository and merges them with your local repository using pull command.

git pull

git branch command lists all the branches present in your repository.

git branch

To switch between the branches present in your repository use below command.

git checkout [branchname]

you can clone repository from remote source to your local machine as below.

git clone "giturl.git"

 



Warning! This site uses cookies
By continuing to browse the site, you are agreeing to our use of cookies. Read our terms and privacy policy