Git – Creating Repository From Scratch – POFTUT

Git – Creating Repository From Scratch


In this chapter we will create users those will be use Git. Create an Git repository and add some code.

Create Users for Git

To use git we need some system users. If we have allready this users we can skip this but if not we will create new users. We will create users for Linux but Windows side is easy to accomplish.

First create a group for developers to sum all developers in this group.

# groupadd dev

Then create a user by adding to this group named dev

# useradd -G dev john

Create password for the new user

# passwd john 
Changing password for user john. 
New password:  
BAD PASSWORD: The password is shorter than 8 characters 
Retype new password:  
passwd: all authentication tokens updated successfully.

BAD PASSWORD is for the password length we have used simple password to make things easy but in real systems use strength password.

Initialize Git Repository

We change our user from root to john.

# su john

We change our current working directory to the john’s home directory

$ cd

We create a directory for our project named myproject.

$ mkdir myproject 
$ ls 
myproject

We open myproject directory and check current path.

$ cd myproject 
$ pwd 
/home/john/myproject

End we can create an empty git repository in this directory

$ git init 
Initialized empty Git repository in /home/john/myproject/.git/

Repository is the location where directory and related files reside. If we list files in the initialized path we can see that a hidden directory named .git is created. It is the core where magic happens.

$ ls -la 
total 12 
drwxrwxr-x 3 john john 4096 Oct  7 03:30 . 
drwx------ 5 john john 4096 Oct  7 03:27 .. 
drwxrwxr-x 7 john john 4096 Oct  7 03:30 .git

We have completed the startup of our git repository. Next Chapter we will start working with our project and codes.

LEARN MORE  Git - Environment Setup and Basic Configuration

Deleting Git Repository

Git repository can be easily deleted without affecting any project file in the current working directory. We know that all git related files reside in the .git hidden folder. So deleting it simple like below will remove git repository.

$ ls -la 
total 16 
drwxrwxr-x 3 john john 4096 Oct  8 03:47 . 
drwx------ 6 john john 4096 Oct  8 03:47 .. 
drwxrwxr-x 8 john john 4096 Oct  8 03:47 .git 
-rw-rw-r-- 1 john john   22 Oct  8 03:47 main.py 
$ rm -Rf .git/

This is same as undo git init command.

Leave a Comment