Turning an ordinary folder into a Git repository is as simple as typing git init. The command converts any folder into a repository in an instant.

Starting Git is as easy as navigating to your project folder in the terminal and typing git init. It begins tracking and creates a default branch.

What's actually happening under the hood?

When you run git init (short for initialize), Git creates a hidden folder called .git inside your project directory. Your project's entire history now lives there — not just the history, but branches, configuration, and a record of who changed what and when.

Think of the .git folder as the version control system's database. If you ever want to stop tracking a project with Git, deleting this folder is all it takes. That said, editing its contents by hand — outside of Git commands — is not recommended.

terminal
# navigate to your project folder
cd my-new-project

# initialize with an explicit branch name
git init -b main

# output
Initialized empty Git repository in /path/to/my-new-project/.git/

A few ground rules for git init

  • Your folder doesn't need to be empty. You can run git init on a project you've been working on for years — Git will simply start tracking it from its current state, without touching any of your files.
  • Don't confuse it with git clone. If you're downloading a repository from GitHub or GitLab, do not run git init — the cloned repo is already initialized.
  • It doesn't connect you to the internet. A common misconception is that git init uploads your project to GitHub or a similar service. It doesn't touch the network at all — it runs entirely locally.
  • Ran it in the wrong folder? Just delete the .git directory that was created. Your code remains untouched. And if you accidentally run git init inside an existing repo, Git simply says "Reinitialized existing Git repository" and makes a few internal adjustments — nothing breaks.
  • Avoid nested repositories. A common mistake for beginners: after running git init in the root of a project, going into a subdirectory (like src/) and running it again. This creates a hidden, untrackable repo inside your main repo.

git init parameters

You can usually just type git init and move on — but the parameters are useful when you need them.

git init The bare minimum. Initializes a repository in the current folder. The default branch name is master unless you've configured init.defaultBranch (introduced in Git 2.28). On older versions, you can follow it up with git branch -M main to rename it.
git init -b <name> Sets a custom name for the initial branch instead of the default. Since GitHub and GitLab both default to main, git init -b main has become the standard starting point for most projects.
git init my-project Creates the folder and initializes the repository in one step — the equivalent of running mkdir, cd, and git init back to back.
git init --bare Creates a repository with no working directory — just the history. Used on servers rather than local machines. You'll typically see this in GitHub/GitLab documentation and server setup guides, not in everyday development.
git init --template Copies pre-made files (hook templates, default config, etc.) into the .git/ folder at initialization time. Handy for sharing a standard Git setup across a team. A genuinely cool Git feature.

Next up: your project is now under Git's watch. Where do you want to go from here? Head over to git add to start staging files, or git status to see what Git is currently seeing.