How To Install Git Server on Ubuntu 22.04

In this tutorial, we will see how to install Git server on Ubuntu 22.04. You will learn to install and configure Git server.

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.


  • A Ubuntu 22.04 installed dedicated server or KVM VPS.
  • A root user access or normal user with administrative privileges.
  • Add DNS A record of your server’s hostname. For example we are using as our server hostname. Or else use your server IP address in the place of

Install Git Server on Ubuntu 22.04

Let’s get started with installation. There are two ways to install Git.

Step 1 is install Git using APT

Keep the server up-to-date

# sudo apt update -y

Install Git

# sudo apt install git -y

Verify the installation:

# git –version

Step 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

# sudo apt install libz-dev libssl-dev libcurl4-gnutls-dev libexpat1-dev gettext cmake gcc -y

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:

# sudo wget

Once the download is complete, we can extract the tar file

# unzip

Now, go to that directory to begin configuring our build.

# cd git-master

Now, you can make the package and install it by typing these two commands:

# sudo make prefix=/usr/local all
# sudo make prefix=/usr/local install

Now, replace the shell process so that the version of Git we just installed will be used:

# exec bash

We have built and installed Git successfully. To verify it check the version using following command:

# git –version

Configure Git

Add user to handle the repositories:

# sudo adduser git

Log in as a git user

# sudo 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 hostnextra.git/hooks/
# cp post-update.sample post-update

That’s it for server side.

Now let’s go to client side:

Install Git

# sudo apt install git -y

Once the installation gets completed, start the configuring the Git

Configure Git

Submit inflammation about yourself so that commit messages will be generated with correct information attached:

# git config –global “git”
# git config –global “[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’…

It will ask to enter git user password:

[email protected]’s password:

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 (root-commit) b337197] My First Commit
1 file changed, 1 insertion(+)
create mode 100644 file1.txt

Push these changes to the remote git repository at

# git push origin master

you will be asked for password, enter git user password

[email protected]’s password:
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 229 bytes | 76.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
* [new branch] master -> master

Verify the changes, access the git server and run following command to check the logs

# git log

Output will be similar like:

commit b3371975bd44fb4aca344e365fa635180967f7fe (HEAD -> master)
Author: git <[email protected]>
Date: Wed Apr 14 10:06:06 2021 +0000

My First Commit

We have successfully install Git server on Ubuntu 22.04.

Related Articles