Header

Creating a repository

How to create a new repository with Git.

Before running the Git command to create the repository, we need to make sure that we’re in the right directory. The process for doing this differs slightly between operating systems.

If you need help getting set up, here’s a handy guide to install and configure Git.

Windows

Open the Command Prompt from Start > Windows System, or by pressing Windows + R then typing cmd and clicking OK.

Windows Command Prompt

If you have created a folder for your project called shop in a Projects folder in your home directory, you’ll need to run the following command:

cd Projects\shop

Alternatively, you can click and drag the folder into the Command Prompt window which will automatically enter the path to the directory.

Now you’re ready to actually create the repository.

Mac

Open the Terminal app which can be found in Applications > Utilities.

Mac Terminal

If you have created a folder for your project called shop in a Projects folder in your home directory, you’ll need to run the following command:

cd ~/Projects/shop

Alternatively, you can click and drag the folder into the Terminal window which will automatically enter the path to the directory.

Now you’re ready to actually create the repository.

Linux

Open the Terminal application from the start menu, or by pressing Ctrl + Alt + T.

Linux Terminal

If you have created a folder for your project called shop in a Projects folder in your home directory, you’ll need to run the following command:

cd ~/Projects/shop

Now you’re ready to actually create the repository.

Actually creating the repository

Now that you’re in the right directory, enter git init in your command line and press enter to create a new empty Git repository. If successful, you should see a message like this:

Initialized empty Git repository in /Users/rob/Projects/shop/.git/

A hidden folder named .git will have just been created inside your project’s working directory. This folder contains all the information Git stores about your repository including historical changes, remote repository addresses, and more.

This .git folder is your local copy of the repository. Deleting the .git folder won’t delete any of the files in your project, however you’ll lose access to all of the historical changes tracked by Git.

In a future tutorial, you’ll learn how to upload your Git repository to a remote server to preserve any local changes, share them, and give everyone else working on the project the ability to download their own local copy of the repository.

Don’t worry if some of this doesn’t make a lot of sense right now. All you need to know is that the .git folder is created by running git init and it is your own version of the project’s repository.

Want to learn more about Git?

This tutorial is part of a free beginner-friendly course!

Learn More