Check all articles

Installation of a Git Server on CentOS 8

When we are developing or when we handle large amounts of documents and we need to save the editions of those documents or source code, we use a versioning repository, we had already made a Installation of SVN in CentOS 7 ... now we are going to install the popular software Git on CentOS 8. For more information on this distributed version control system (that is free and open source), you can visit its web site.

The installation and configuration of git is very simple, but it is necessary that the reader has basic knowledge in Linux. For a reference on how to install CentOS 8, please review our article Installation of CentOS 8.

Once we have the server available, we start:

Initial considerations

For an efficient installation of git we must take into account:

  • Have root user access: to install packages, create users, create groups, create directories, etc.
  • Estimate as far as possible the space to be used and the growth of space use (dimensioning & capacity planning).
  • Have a RAID redundancy on the disks if it is for production. I recommend RAID-5.
  • Use SSD (solid-state drive), if your repository is going to generate a lot of activity.
  • Open only the necessary firewall ports on the server, 9418 (git://).
  • If the server is within a VLAN for development use only, configure QoS (Quality of Service) on the Switch for this server.
  • Establish a backup and recovery strategy.
  • Install the latest available operating system packages.
  • If possible synchronize the server clock, NTP (Network Time Protocol).
  • Static IP address and if you are going to have access from the internet do the NAT (Network Address Translation) towards a public IP.
  • Important note: if you are publishing your repository on the internet, it must be in the DMZ.
  • If you are going to use other clients to use git, make sure that the firewall ports are open: 22 (ssh), 80 (http), 443 (https).

Software installation

With root user or sudo, execute:

$ su - 
# dnf -y install git

Check the version

Once the installation is finished we check the version of git. For Dec/27/2019, the available version is 2.18.1:

# git --version 

Create user group

We will create a user group for repository permissions:

# groupadd reposcm 

Administrator User Creation

We will create a repository administrator user:

# useradd –g reposcm -c "Git Admin" gitadmin
# passwd gitadmin

Create a directory

The repository will be created where you need it, if it has an external storage it should be directed to that point. In my case I will create it in the directory /var

# cd /var
# mkdir gitrepo
# chmod g+rwx /var/gitrepo
# chown :reposcm /var/gitrepo
# chown gitadmin /var/gitrepo

Initialize our repository

Configure our repository, we connect with the user gitadmin:

$ cd /var/gitrepo 
$ mkdir repositorio.git 
$ cd repositorio.git 
$ git init --bare 
$ git config core.sharedRepository true 
$ git config receive.denyCurrentBranch ignore 

Verify the configuration

Here we have configured our server, to check the configuration in git, use:

$ git config --list 

Creating a repository user

Create a user, you must create users as many as you need with user root, execute:

# useradd –g reposcm -c "Ing. Juan Leon" juanleon 
# passwd juanleon

Set your identity

Configure our identity in the repository, it can be on the same server to do some tests (for me the user is juanleon):

$ git config –-global "Juan Leon" 
$ git config –-global 

The first commit

Create a test file for our first commit, logged in with my user juanleon.

$ cd /home/juanleon
$ git clone ssh://juanleon@centos8/var/gitrepo/repositorio.git
$ cd repositorio 
$ touch this_is_a_test.txt 
$ git add . 
$ git commit –m "my first commit" 

And Ready!!!

We have our own git server using CentOS 8. Now we can access our repository from our favorite IDE (Integrated Development Environment), for me Visual Studio and Eclipse. You may also be used to access github ... if you want to be able to navigate in your repository from the web you can install gitlab.