Learning navigation

Code with Animation

Initializing a Repository

How to turn a normal folder into a Git repository using `git init`.

Version Control3 min readConcept 3 of 29

git init

The git init command is how you start using Git in an existing project. It transforms a standard folder on your computer into a Git repository.

You only ever need to run this command once per project.

Why it matters

Before you run git init, Git has no idea your folder exists. You can't track changes, create branches, or commit code.

Running this command is the required first step before you can use any other Git features locally.

How it works under the hood

When you run git init, Git doesn't change any of your project's files. Instead, it creates a single, hidden folder called .git at the root of your project.

This .git folder is the actual 'Repository' (Tree #3 from the Three Trees). It contains all the internal plumbing Git uses to store your snapshots, branches, and config. If you delete the .git folder, the folder stops being a repository entirely, but your actual code files remain intact.

See what git init creates

Inspect the repository database beside the project files that Git leaves unchanged.

~/projects/my-app $ git init
Initialized empty Git repository in /Users/me/projects/my-app/.git/
~/projects/my-app $ ls -la
total 0
drwxr-xr-x 4 me staff 128 Oct 10 10:00 .
drwxr-xr-x 10 me staff 320 Oct 10 9:59 ..
drwxr-xr-x 10 me staff 320 Oct 10 10:00 .git
my-app/
.git/(The Repository)

Ordinary git init creates a .git directory for repository data while leaving your project files in place. This is an illustrative directory listing.

Check yourself

Pick an answer to lock it in, then read why. Getting one wrong is part of how it sticks.

  1. 1What exactly does the `git init` command do to your project files?
  2. 2How many times do you need to run `git init` in a single project?
  3. 3What happens if you delete the hidden `.git` folder?

Remember this

  • Run git init once per project.
  • It creates the hidden .git directory.
  • Never run it in your home directory.

Done with this concept?

Mark it complete to track your progress. No login needed.