How do you create local Git repository?

Experience Level: Junior
Tags: Git Source control

Answer

Your local repository can be created in two ways:

Create empty repository

When you start a new project, you usually want to create a new empty repository. This can be done by executing the following command from the command line:

git init

The command above will create the new repository in your current folder. You can also run the following command:

git init <NameOfYourRepository>

The command above will create the new repository in the folder <NameOfYourRepository>. The folder for the new repository will be created in your current folder.

Clone existing repository

When you join an existing project, you usually want to clone already existing repository. This can be done by executing the following command from the command line:

git clone <AddressToYourRepo>

The remote repository will be downloaded to your local computer as a local repository. The remote repository is often called Upstream, the local repository is called Downstream.

Related Git job interview questions
Git for beginners
Git for beginners

Are you learning Git? Try our test we designed to help you progress faster.

Test yourself