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
This is the easy way to install through yum.For this first we need to enable IUS repository or Wandisco GIT Repository
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
Compiling from source code
If you want to compile latest version of git from source code then follow below steps.
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
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
git version 2.23.0
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 "firstname.lastname@example.org" git config --list
user.name=Your Name email@example.com
That's it.Git has been successfully installed on your system.
Also Read -> How to Install Webmin on Centos 7
To initiate a new git repository,use following command.
To check status of files in index versus working directory for your git repository.
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.
This will push the changes into the master branch.
To check the commit log
git fetches the changes of the remote repository and merges them with your local repository using pull command.
git branch command lists all the branches present in your repository.
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"