Open In App
Related Articles

Git- Setting up a Repository

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

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 .

Using git init command

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

  • -q–quiet Only print error and warning messages. All other output is silenced.
  • –bare It creates a bare repository. It is used when you are collaborating with other developers and need a space to share each other’s changes. For this, a bare repository is created at a central place where everyone can push their changes.
  • –template=(template_directory) It specifies the directory from which files are copied into the repository.
  • –SHARED[=(FALSE|TRUE|UMASK|GROUP|ALL|WORLD|EVERYBODY|0XXX)] It sets the access permissions for the new repository. Few Examples are:-
  • group (or true): Make repository group- writable.
  • all (or world or everybody) :-Same as group, but make the repository readable by all users.

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

  • –branch It allows you to point to the branch pointed to the cloned repository’s head instead of pointing to newly created head.
  • –template It clones the repository at and applies the template form to the newly created local branch.

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.


Last Updated : 01 Nov, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads