Skip to main content
Back to command reference
Getting Started

git init

Create a new Git repository

Practical example

bash
git init my-project
cd my-project
# .git folder is created automatically

Command overview & how it works

Creates a .git subdirectory that initializes the repository metadata structure — this is the first command you run to start tracking changes in a project. Running git init in an existing directory does not overwrite anything; it is safe to re-run. The generated .git folder stores all commit objects, refs, configuration, and hooks. Use git init --bare to create a server-side repository without a working directory, and git init --template to specify a custom template directory for your hooks and config files. This command only creates the local repository — you still need git remote add to connect it to a remote server.

Chapter 01 · Mental Model & Architecture

Get the complete offline Git Field Guide

The 97-page PDF + ePub course — ₹499. Read this command, offline.

Learn more

Practical tips

  • Running git init on an existing repository is safe — it re-initializes the repository without deleting your history.
  • Use git init --bare to create a server-side repository that others can clone from and push to.
  • Inspect what was created with ls -a .git to see the object database, refs, HEAD, and config files.

Deep-dive guides & tutorials

In-depth walkthroughs and practical scenarios related to git init

All guides →
  • Guide

    How to Install Git on Windows, macOS, and Linux

    A step-by-step setup guide covering every major platform, from Homebrew and Winget to package managers, plus verifying your install and configuring your identity.

    7 min readRead guide
  • Tutorial

    Git Basics Every Developer Should Know

    Understand the core concepts — repositories, commits, branches, and remotes — before diving into the command line.

    6 min readRead guide
  • Guide

    How to Write Better Git Commit Messages

    A practical guide to writing clear, conventional commit messages that make your project history readable and your team more productive.

    6 min readRead guide

Related commands

More from Getting Started