Git Create Repository
Generally, users host their repository on online git management providers like Github.com, bitbucket.com, and Gitlab.com. 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 on your Linux server. After that clone that repository to your local system for development purpose.
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 repository to the server from client systems.
rahul@tecadmin:~$ sudo adduser git Adding usergit' ... Adding new group
git' (1044) ... Adding new usergit' (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 project directory. Try to keep repository name ending with .git for the better naming convention.
rahul@tecadmin:~$ sudo su - gitgit@tecadmin:~$ mkdir projects && cd projectsgit@tecadmin:~/projects$ mkdir app1.git && cd app1.git
Now use following command to initialize repository. Do not forgot to use –bare keyword in command to create 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 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 clients system using the following command. This will ask for password of git user.
$ git clone [email protected]:projects/app1.git
The next tutorial, you will learn how to set up key-based ssh access and clone git repositories over ssh without password.