Skip to main content

How to Create a Git Repository (And What a Repo Actually Is)

Short answer

To create a new local Git repository, navigate to your project directory and run git init, which creates a hidden .git folder that Git uses to track all changes to files in that directory. After initialising, add your project files to the index with git add . and make the first commit with git commit -m "Initial commit". To link the local repository to a remote (e.g., on GitHub), create an empty repository on the platform first, then connect it locally with git remote add origin <url> and push with git push -u origin main. Alternatively, use git clone <url> to create a local copy of an existing remote repository in one command — this downloads the full history and automatically sets up the origin remote. Choose git init when starting a brand-new project locally, and git clone when you want to work on an existing repository that already lives on a remote server. If a Git command fails with "fatal: not a git repository (or any of the parent directories): .git", you are running it outside of a repository — change into the correct project folder, or run git init to initialise one.

When you're starting a new coding project (or joining an existing one) the first thing to do is create (or clone) the project's Git repository. But what exactly is a repository?

A Git repository (or "repo") is at its core a special, hidden directory named .git located at the root of your project folder. This is where Git stores the complete record of your project's history:

  • Commits are like snapshots or "save points" in your project. Each time you reach a good stopping point, you can create a commit to save the state of your entire project — and flip back to any of these saved points later.
  • Branches let you create a separate copy of your project to try out a new idea or feature, without affecting the main codebase. If you like the result, you can merge it back in.
  • Tags mark important milestones, making it easy to find and revisit specific versions later.

The Git Cheat Sheet

No need to remember all those commands and parameters: get our popular "Git Cheat Sheet" - for free!

Free. We email you a ZIP with our cheat sheets.


Creating a Brand New Repository

If you want to start a new project and put it under version control with Git, use git init:

#1: Create a folder for this project on your local hard drive
$ mkdir my-project

#2: Change into this folder
$ cd my-project

#3: Initialize a new, empty Git repository here
$ git init

...after having written some code and created some files...
#4: Add all changes to the next (= first) commit
$ git add .

#5: Create this first commit
$ git commit -m "Initial commit"

Note that git init only creates a blank repository — it does not automatically add any existing files in the directory to version control. It's your responsibility to then deliberately add files and create commits.


No Command Line Needed

Creating a Repository in Tower

In case you are using the Tower Git client, you can simply drag and drop your project folder — and then create your first commit with a couple of simple clicks:

Cloning an Existing Repository

If you want to join an existing project that has already been started by someone else, you have to clone it. Cloning a repository from a remote server means downloading it to your computer so you can work on the project:

#1: Move to the location where you want to download the project
$ cd my-projects

#2: Download the project by cloning it
$ git clone https://github.com/gittower/git-crash-course.git

You might then have to provide your authentication details — and will then have the complete project, including all of its history, on your computer and ready to contribute to.


No Command Line Needed

Cloning a Repository in Tower

In case you are using the Tower Git client, cloning a project is very easy: after you've connected your GitHub / GitLab / Bitbucket / ... account to Tower, you don't have to worry about usernames, passwords, or tokens anymore. You'll have access to all of your repositories on the remote server — and can clone any of them with just a single click:

Local and Remote Repositories

There are two main types of Git repositories:

  • Local Repository: This is the repository that lives on your own computer. It's where you do all your work: creating new files, making changes, and committing them.
  • Remote Repository: This is a repository hosted on a server, usually on a platform like GitHub, GitLab, or Bitbucket. A remote repository allows you to share your work with others, collaborate on projects, and back up your code.

You can have multiple remote repositories for a single project, but it's most common to have one central repository that everyone on the team uses to stay in sync.

The .git Directory

Every Git repository has a hidden .git folder at its root. This is where all of Git's internals live:

  • objects: Stores all the snapshots of your files as Git objects.
  • refs: Stores pointers to your commits, such as branches and tags.
  • HEAD: Points to the currently checked-out branch.
  • config: Contains repository-specific configuration settings.

You should never manually edit files inside .git — Git manages this directory entirely on its own.

"fatal: not a git repository" — What This Error Means

Sooner or later, you'll probably run a Git command and be greeted by this message:

fatal: not a git repository (or any of the parent directories): .git

Git is telling you that neither the current directory nor any of its parent directories contains a .git folder — in other words, you're not inside a Git repository. The most common causes are:

  • You're in the wrong directory. Simply cd into your project folder and try again.
  • The project isn't under version control yet. Run git init to create a repository, as shown above.
  • You downloaded the project as a ZIP archive instead of cloning it. A ZIP download doesn't include the .git folder — clone the repository with git clone <url> to get a working copy with its full history.

Free download

Download the Cheat Sheet

Get 18 of our most popular Cheat Sheets in one handy ZIP!