GIT

Create Git Repository

A Git repository is the .git/ folder inside a project. This repository tracks all changes made to files in your project, building a history over time. Meaning, if you delete the .git/ folder, then you delete your project’s history.

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.

Create User Git as a 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.

$ 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

Create a 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.

$ sudo su - git 
$ mkdir projects && cd 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 --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.

$ 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

That’s all.

FAQs

Question 1 : How can I create a git repository?

Answer : To create a git repository follow the below steps:

  1. Create a system user running “sudo adducer git”.
  2.  Create a Bare repository.
  3.  Add file into it.

Question 2 : How do I create a  git project?

Answer : There are two options first you can use your local repository that is currently not under version control. Second you can clone an exiting repository.

Question 3 : How do I add a fine into git?

Answer : To add a file into git run git add –all or git add . command at the terminal in your local project directory. Now type git status command view the changes.

Thank you! for visiting LookLinux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at Look Linux Submit Article. Stay connected to Facebook.

About the author

mm

Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

Leave a Comment