In this tutorial, we will see how to install and configure git server on CentOS 7
Git is a distributed version-control system for tracking changes in source code during software development. It is designed for coordinating work among programmers, but it can be used to track changes in any set of files. Its goals include speed, data integrity, and support for distributed, non-linear workflows.
Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
Let’s get started with installation.
There are two options to install Git.
Option 1 is install Git using Yum
1. Keep the server up-to-date
# yum update -y
2. Install Git
# yum install git -y
Option 2 is install git from source
You can download latest version of Git from release page. It make take longer time and will not be updated and maintained through the yum package manager. But it will allow you to download a newer version than what is available through the CentOS repositories, and will give you some control over the options that you can include.
First, install dependencies
# yum groupinstall "Development Tools"
# yum install gettext-devel openssl-devel perl-CPAN perl-devel zlib-devel
After the installation complete, go to release page and copy the download link. You can find tar.gz, right click on it and copy the link.
Now, download it in the server using wget command and rename it:
# wget https://github.com/git/git/archive/v2.14.6.tar.gz -O git.tar.gz
Once the download is complete, we can extract the tar file
# tar -zxf git.tar.gz
Now, go to that directory to begin configuring our build.
# cd git-*
We can check for everything that we need with the configure script that is generated by make configure. This script will also use a --prefix to declare /usr/local (the default program folder for Linux platforms) as the appropriate destination for the new binary, and will create a Makefile to be used in the following step.
# make configure
# ./configure --prefix=/usr/local
Makefiles are scriptable configuration files that are processed by the make utility. Our Makefile will tell make how to compile a program and link it to our CentOS installation so that we can execute the program properly.
# make install
We have built and installed Git successfully. To verify it check the version using following command:
# git --version
Set Up Git
Add user to handle the repositories:
# useradd git
Then give your Git user a password:
# passwd git
Log in as a git user
# su - git
Initiate a new empty repository using following command:
# git init --bare ~/hostnextra.git
Enable post-update hook by copying the sample file as follows:
# cd hooks/
# cp post-update.sample post-update
That’s it for server side.
Now let’s go to client side:
# yum install git -y
The installation is completed
Set up git
Submit inflammation about yourself so that commit messages will be generated with correct information attached:
# git config --global user.name "git"
# git config --global user.email "[email protected]"
Create a directory where you can keep all your projects
# mkdir ~/dev
# cd ~/dev
Now, create a clone the hostnextra.git repository that we have created earlier in the server
# git clone [email protected]:~/hostnextra.git hostnextra.git
Cloning into 'hostnextra.git’…
warning: You appear to have cloned an empty repository.
Go to respository
# cd hostnextra.git
You can see the repository is empty, so lets create some files
# echo "my test file" > file1.txt
Add these file to our git repository
# git add .
Commit the changes
# git commit -am "My First Commit"
[master 45fc94c] added test file
1 file changed, 1 insertion(+)
create mode 100644 file1.txt
Push these changes to the remote git repository at git-server.lab.com
# git push origin master
you will be asked for password, enter git user password
[email protected]’s password:
Counting objects: 2, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 235 bytes | 235.00 KiB/s, done.
Total 2 (delta 0), reused 0 (delta 0)
bc172aa..45fc94c master -> master
Verify the changes, access the git server and run following command to check the logs
# git log
We have successfully install and configure Git server on CentOS 7
[Need assistance to fix this error or install tools? We’ll help you.]