Back to Top

How to use Git init command

to-use-git-init-command

Nowadays, Most used version control software is Git, right? If you still use SVN or CVS, try out Git and you will never go back to SVN or CVS!. Github is a web site that uses Git to host code or we can say GitHub is the interface of Git for users. There are two ways to host the code in GitHub, one is public, anyone can download and upload code and the other is private. Private is paid version where only the creator of the code can see, download or upload code.

Git init command

Git init command is used when we want to convert a simple project to Git compatible project. If you already have a Git project then you don’t need this command for the project. You can just clone the project from the GitHub URL.

To see how to clone a git project you can visit the section “Create GitHub project using Git software” of my previous article here.

Now getting back to this article, we will learn in deep about init command. We will also see the difference and use of “Git init –bare” command as well.

Creating a Simple Git project

There is two ways of creating Git project. The first way is to create the GitHub project and clone it in Local Git Repository. The second way is to use Git init command to initialize Git project in local Desktop/Laptop. Set the remote origin Git URL of the project. Yes, but you always have to create the GitHub account in both cases.

Creating a Central Git project

The central or main Git project refers to the project which is on a central server or main server. Every developer pulls(Latest update) and pushes(Check-In) code on this central Git project. There is a different way to create such central project in Git. You need the “git init –bare” command to create the central Git project. Maybe it is confusing but below image will help you to get a clear idea.

In the above figure, the Central Git project is created using the git init bare command. The Central Git project can be on Github.com or on your local machine or on your central server. While the simple git projects are created by using git init/git clone by developers. Now we will see how to create a Central Git project.

Now we will see how to create a Central Git project through steps mentioned below.

Create a new directory with .git extension as shown below. I have created on the D drive of my local machine. Use below command to do it.

Git init bare directory

Now execute the git bare command to make the project a Central Git Project. See the below command and image.

Git Init Bare Command

The main thing to remember is bare repository does not contain the code base of the project. It just contains the status of the branches and everything that requires maintaining a central repository. Below image shows the content of the bare repository.

Git Init D directory

As shown in above image the bare repository contains the same folders that will be present in your simple project’s “.git” directory. It will not have the actual code base. So this is the basic difference between git init and git bare command.

Hope you liked this article. Do comment below and leave feedbacks. Your suggestions are always welcome.

Share:
Share on Facebook1Share on LinkedIn1Tweet about this on TwitterShare on Google+0Buffer this pageDigg thisShare on Reddit1

Leave a Reply

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

Most Popular Posts

How to use HTML5 Constraint Validation

Posted on 2 years ago

Bhumi

How to handle Exception in PHP5

Posted on 2 years ago

Bhumi

How To set up Signup Bonus in X-Cart

Posted on 5 years ago

Bhumi

Facade implementation in Laravel

Updated 1 month ago

Bhumi

MySQL coalesce() function

Updated 18 years ago

Bhumi

How to use JavaScript Promise API?

Updated 18 years ago

Bhumi

What are Lambdas and Closures in PHP?

Updated 18 years ago

Bhumi

The Reader’s Poll – June 2015

Posted on 2 years ago

Bhumi

The Reader’s Poll – August 2014

Posted on 3 years ago

Bhumi

The Reader’s Poll – June 2014

Posted on 3 years ago

Bhumi

The Readers’ Poll – May 2014

Posted on 3 years ago

Bhumi

The Readers’ Poll – August 2013

Posted on 4 years ago

Bhumi