How to Initialize a New Git Repository (git init)

git init creates a new, empty Git repository in the current directory by adding a hidden .git folder that stores all version history.

Published September 26, 2026

git init turns the current folder into a Git repository by creating a hidden .git directory that stores all history and settings. It is the first command in any new project.

How it works

Nothing is tracked yet: the repository starts empty on a default branch (main or master). You then add files and make a first commit.

You can also initialise in a new folder with git init <name>, or create a bare repository for a server with --bare.

Try it

mkdir my-app && cd my-app
git init
Initialized empty Git repository in /my-app/.git/
git status
On branch main No commits yet

Practical examples

Start a project

git init
git add .
git commit -m "Initial commit"

Choose the branch name

git init -b main

Connect to a remote

git remote add origin git@github.com:me/my-app.git
git push -u origin main

Bare repo on a server

git init --bare project.git

Common mistakes

  • Running git init inside an existing repo or home directory by mistake.
  • Forgetting a .gitignore before the first git add .
  • Deleting the .git folder, which erases all history.

Key takeaways

  • git init creates the .git folder.
  • Add, commit, then connect a remote.
  • Never initialise inside another repository.

FAQ

Does git init delete anything?

No, it is safe to re-run in an existing repository.

How do I undo it?

Delete the .git directory to remove the repository (and its history).

More Git articles