Open In App

Git- Setting up a Repository

What is Repository?

In simple terms, it is the central location in which data is stored or managed. A



git repository

virtually stores a particular file and allows you to save and access it’s version.



Initializing a Repository

To create a new repository the

git init

command is used. It is used to convert an existing project to git repository.This is the first and one time command we use during initialization of a new repository. When git init command is executed,

.git

subdirectory is created.This includes subdirectories for objects,template files etc. An initial head file or new master branch is also created.

git init (directory)

This creates an empty git repository to the specified .

git init command initializes the repository

NOTE:

Running git init on a project directory that already contains .git subdirectory will not override existing .git configuration on using git init again.

Configuration

Git Clone

This command is used when the project is already their in the central repository.Like git init, git clone is also one time command.

git clone (repository URL) 

git clone is used to create a copy of remote repositories. We pass git clone a repository URL.

Following Images shows the cloning of repository file from github into the local repository directory

Options

Other options are

–mirror, –bare, –origin

and many more.

Summarizing-

git init

VS

git clone

Very simple way to distinguish them is to note the point that git clone is dependent on git init. git clone is used to create a copy of existing repository but git clone itself first calls git init to create new repository.

Article Tags :