Git Create Repository

Git Create Repository

 Git Create Repository

Generally, users host their repository on online git management providers like,, and But you can also host your repository on your server without any management tool. This is helpful for small organizations with limited git repositories.

Follow instructions to create your own bare repository and host it on your Linux server. After that clone that repository to your local system for development purposes.

Create System User

First, create a new system user, This is a good practice to have a separate user, which will be used to connect the repository to the server from client systems.

rahul@tecadmin:~$ sudo adduser git 

Adding user git' ...
Adding new group git' (1044) ...
Adding new user git' (1044) with group git' ...
Creating home directory /home/git' ...
Copying files from /etc/skel' ...
Enter new UNIX password: *********
Retype new UNIX password: *********
passwd: password updated successfully
Changing the user information for git
Enter the new value, or press ENTER for the default
	Full Name []:
	Room Number []:
	Work Phone []:
	Home Phone []:
	Other []:
Is the information correct? [Y/n] y

Crete Bare Repository

Now create a git bare repository. This repository will be used as a remote repository by developers. First, we are creating a project directory. After that, I will create our first git repository named app1.git inside the project directory. Try to keep the repository name ending with .git for a better naming convention.

rahul@tecadmin:~$ sudo su - git 
git@tecadmin:~$ mkdir projects && cd projects 
git@tecadmin:~/projects$ mkdir app1.git && cd app1.git 

Now use the following command to initialize the repository. Do not forget to use –the bare keyword in the command to create a bare repository.

git@tecadmin:~/projects/app1.git$  git --bare init 

Initialized empty Git repository in /home/git/projects/app1.git/

If you list files inside the repository you will not find a directory named .git due to the bare repository, You will see their many files like below

git@tecadmin:~/projects/app1.git$  ls -l 

total 32
drwxrwxr-x 2 git git 4096 Oct  8 12:33 branches
-rw-rw-r-- 1 git git   66 Oct  8 12:33 config
-rw-rw-r-- 1 git git   73 Oct  8 12:33 description
-rw-rw-r-- 1 git git   23 Oct  8 12:33 HEAD
drwxrwxr-x 2 git git 4096 Oct  8 12:33 hooks
drwxrwxr-x 2 git git 4096 Oct  8 12:33 info
drwxrwxr-x 4 git git 4096 Oct  8 12:33 objects
drwxrwxr-x 4 git git 4096 Oct  8 12:33 refs

Clone Repository

Now you can make a clone of this repository from any client's system using the following command. This will ask for the password of the git user.

$ git clone

In the next tutorial, you will learn how to set up key-based ssh access and clone git repositories over ssh without a password.


Post a Comment