Install and Configure Git Server on AlmaLinux 8
Tags: github, gitserver, almalinux, linux
Published: 2021-08-27 05:22:22

<!-- wp:paragraph -->
<p>In this tutorial, we'll explain how to install and configure git server on AlmaLinux 8</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>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.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>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.</p>
<!-- /wp:paragraph -->

<!-- wp:html -->
<a href="https://neutroncloud.in/docs/install-and-configure-git-server-on-almalinux-8/">Install and Configure Git Server on AlmaLinux 8</a>
<!-- /wp:html -->

<!-- wp:paragraph -->
<p>There are two options to install Git.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":4} -->
<h4>Option 1 is install Git using dnf</h4>
<!-- /wp:heading -->

<!-- wp:heading {"level":5} -->
<h5>1. Keep the server up-to-date</h5>
<!-- /wp:heading -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><p># dnf update -y</p></blockquote>
<!-- /wp:quote -->

<!-- wp:heading {"level":5} -->
<h5>2. Install Git</h5>
<!-- /wp:heading -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><p># dnf install git -y</p></blockquote>
<!-- /wp:quote -->

<!-- wp:heading {"level":4} -->
<h4>Option 2 is install git from source</h4>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>You can download latest version of Git from <a href="https://github.com/git/git/releases" target="_blank" rel="noreferrer noopener"><em><strong>release page</strong></em></a>. It make take longer time and will not be updated and maintained through the dnf package manager. But it will allow you to download a newer version, and will give you some control over the options that you can include.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>First, install dependencies</p>
<!-- /wp:paragraph -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><p># dnf groupinstall "Development Tools"<br># dnf install gettext-devel openssl-devel perl-CPAN perl-devel zlib-devel wget -y</p></blockquote>
<!-- /wp:quote -->

<!-- wp:paragraph -->
<p>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.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Now, download it in the server using wget command and rename it:</p>
<!-- /wp:paragraph -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><p># wget https://github.com/git/git/archive/refs/tags/v2.33.0.tar.gz -O git.tar.gz</p></blockquote>
<!-- /wp:quote -->

<!-- wp:paragraph -->
<p>Once the download is complete, we can extract the tar file</p>
<!-- /wp:paragraph -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><p># tar -zxf git.tar.gz</p></blockquote>
<!-- /wp:quote -->

<!-- wp:paragraph -->
<p>Now, go to that directory to begin configuring our build.</p>
<!-- /wp:paragraph -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><p># cd git-*</p></blockquote>
<!-- /wp:quote -->

<!-- wp:paragraph -->
<p>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.</p>
<!-- /wp:paragraph -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><p># make configure<br># ./configure --prefix=/usr/local</p></blockquote>
<!-- /wp:quote -->

<!-- wp:paragraph -->
<p>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.</p>
<!-- /wp:paragraph -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><p># make install</p></blockquote>
<!-- /wp:quote -->

<!-- wp:paragraph -->
<p>We have built and installed Git successfully. To verify it check the version using following command:</p>
<!-- /wp:paragraph -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><p># git --version</p></blockquote>
<!-- /wp:quote -->

<!-- wp:heading {"level":4} -->
<h4>Set Up Git</h4>
<!-- /wp:heading -->

<!-- wp:heading {"level":5} -->
<h5>Add user to handle the repositories:</h5>
<!-- /wp:heading -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><p># useradd git</p></blockquote>
<!-- /wp:quote -->

<!-- wp:heading {"level":5} -->
<h5>Then give your Git user a password:</h5>
<!-- /wp:heading -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><p># passwd git</p></blockquote>
<!-- /wp:quote -->

<!-- wp:heading {"level":4} -->
<h4>Log in as a git user</h4>
<!-- /wp:heading -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><p># su - git</p></blockquote>
<!-- /wp:quote -->

<!-- wp:heading {"level":5} -->
<h5>Initiate a new empty repository using following command:</h5>
<!-- /wp:heading -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><p># git init --bare ~/hostnextra.git</p></blockquote>
<!-- /wp:quote -->

<!-- wp:heading {"level":5} -->
<h5>Enable post-update hook by copying the sample file as follows:</h5>
<!-- /wp:heading -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><p># cd hooks/<br># cp post-update.sample post-update</p></blockquote>
<!-- /wp:quote -->

<!-- wp:paragraph -->
<p>That's it for server side.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":4} -->
<h4>Now let's go to client side:</h4>
<!-- /wp:heading -->

<!-- wp:heading {"level":5} -->
<h5>Install Git</h5>
<!-- /wp:heading -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><p># dnf install git -y</p></blockquote>
<!-- /wp:quote -->

<!-- wp:paragraph -->
<p>The installation is completed</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":4} -->
<h4>Set up git</h4>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Submit inflammation about yourself so that commit messages will be generated with correct information attached:</p>
<!-- /wp:paragraph -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><p># git config --global user.name "git"<br># git config --global user.email "git@git-client.lab.com"</p></blockquote>
<!-- /wp:quote -->

<!-- wp:heading {"level":5} -->
<h5>Create a directory where you can keep all your projects</h5>
<!-- /wp:heading -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><p># mkdir ~/dev<br># cd ~/dev</p></blockquote>
<!-- /wp:quote -->

<!-- wp:paragraph -->
<p>Now, create a clone the hostnextra.git repository that we have created earlier in the server</p>
<!-- /wp:paragraph -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><p># git clone git@git-server.lab.com:~/hostnextra.git hostnextra.git<br>Cloning into 'hostnextra.git'...<br>warning: You appear to have cloned an empty repository.</p></blockquote>
<!-- /wp:quote -->

<!-- wp:heading {"level":5} -->
<h5>Go to respository</h5>
<!-- /wp:heading -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><p># cd hostnextra.git</p></blockquote>
<!-- /wp:quote -->

<!-- wp:paragraph -->
<p>You can see the repository is empty, so lets create some files</p>
<!-- /wp:paragraph -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><p># echo "my test file" &gt; file1.txt</p></blockquote>
<!-- /wp:quote -->

<!-- wp:heading {"level":5} -->
<h5>Add these file to our git repository</h5>
<!-- /wp:heading -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><p># git add .</p></blockquote>
<!-- /wp:quote -->

<!-- wp:heading {"level":4} -->
<h4>Commit the changes</h4>
<!-- /wp:heading -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><p># git commit -am "My First Commit"<br>[master 45fc94c] added test file<br>1 file changed, 1 insertion(+)<br>create mode 100644 file1.txt</p></blockquote>
<!-- /wp:quote -->

<!-- wp:heading {"level":5} -->
<h5>Push these changes to the remote git repository at git-server.lab.com</h5>
<!-- /wp:heading -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><p># git push origin master</p></blockquote>
<!-- /wp:quote -->

<!-- wp:paragraph -->
<p>you will be asked for password, enter git user password</p>
<!-- /wp:paragraph -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><p>git@git-server.lab.com's password:<br>Counting objects: 2, done.<br>Delta compression using up to 4 threads.<br>Compressing objects: 100% (2/2), done.<br>Writing objects: 100% (2/2), 235 bytes | 235.00 KiB/s, done.<br>Total 2 (delta 0), reused 0 (delta 0)<br>To git-server.lab.com:~/hostnextra.git<br>bc172aa..45fc94c master -&gt; master</p></blockquote>
<!-- /wp:quote -->

<!-- wp:paragraph -->
<p>Verify the changes, access the git server and run following command to check the logs</p>
<!-- /wp:paragraph -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><p># git log</p></blockquote>
<!-- /wp:quote -->

<!-- wp:paragraph -->
<p>We have successfully install and configure Git server on AlmaLinux 8</p>
<!-- /wp:paragraph -->