git init

What is git init command ?

Git init command creates a new git repository. It is initial command from the list of git commands.  This tutorial includes , how to create git repository on linux. Example in this tutorial are based on CentOs  and git is already installed on the machine.

Type of git repository?

Now you have decided to create a repository for you and your team?  What options should you use in git init command or git init is all you need only?

git init command , creates a repository with actual files. The directory created is the working directory. Directory includes a  full working tree.  The directory , have .git directory folder for all revision history. All files present in working directory are as checkout copies of all files. This is suitable for you , if you are the only user of repository.I guess here not as you have team. Want git repository to be accessible to all developers.

Other type of repository is bare repository. Bare git repository is created by using --bare option in git init command. Bare repository can be shared among multiple developers over the network. Developers need to know the URL and login credentials for the repository.

You want to avail repository to all developer in your team, so creating a bare repository is good for you.

Git repository server location:

From where the git repository will accessed? From inside office premises (over LAN)? Or from any where ? If from any where, then the repository hosting sever should have public ip or you can also choose existing platforms github ,bitbucket etc.

If due to limitation or any other factor , if requirement is , give access from office premises/LAN only . Then a machine on LAN (Local Area Network, have internal ip address ) is suitable option.

In this tutorial the git repository will be created on a linux machine in LAN. The ip address of machine which will host the git repository is . The git user is the root user of linux machine. You can create a new user/users for accessing git repository. For simplicity user is root in this example.

Create git bare repository:

After ssh on machine

[root@CentOS_6_64-159 ~]# cd /
[root@CentOS_6_64-159 /]#
[root@CentOS_6_64-159 /]# mkdir myrepository.git
[root@CentOS_6_64-159 /]# cd myrepository.git/
[root@CentOS_6_64-159 myrepository.git]#
[root@CentOS_6_64-159 myrepository.git]# git --bare init

The Above will create a bare repository , now assign the bare repository a working tree.

  • Do SSH  on another machine ( in same LAN.
  • Will create a local repository (git init command),
  • Add a new file (git add command) and commit the new file (git commit).
  • Push the code changes to central repository.
[root@CentOS_6_64-160 gitdevelopment]# git init
[root@CentOS_6_64-160 gitdevelopment]# git add firstFile.c
[root@CentOS_6_64-160 gitdevelopment]# git commit -m "First Commit to Bare Bepository"
[root@CentOS_6_64-160 gitdevelopment]# git remote add origin root@
[root@CentOS_6_64-160 gitdevelopment]# git push origin masterNote: It will prompt for password, enter the password for user root on machine

The remote repository is ready with working tree. Other user will clone from machine  to the machine, in same LAN. Ssh to machine. The git clone command is in git , so clone a git repository on local machine.

[root@CentOS_6_64-155 gitexample]# git clone root@
Note: It will prompt for password, enter the password for user root on machine[root@CentOS_6_64-155 gitexample]# cd myrepository/Note : You can see the file ,[root@CentOS_6_64-155 myrepository]# ls
[root@CentOS_6_64-155 myrepository]#
Note: Now add a new file secondFile.c, first create file with vim.[root@CentOS_6_64-155 myrepository]# git add secondFile.c
[root@CentOS_6_64-155 myrepository]# git commit -m "Added Second File"
[root@CentOS_6_64-155 myrepository]# git push
Note: It will prompt for password, enter the password for user root on machine


Great 🙂 , git repository is ready. Invite developers to work on this.


Leave a Comment

Your email address will not be published. Required fields are marked *