basics

git init

Creates a new empty Git repository by initializing the .git metadata directory in the current or specified folder. Turns any directory into a version-controlled project.

git init [<directory>]

Common flags

Flag Purpose
-b <name> Set the initial branch name (e.g., main)
--bare Create a bare repo with no working tree, typical for servers
--initial-branch=<name> Explicit form of -b for the default branch
--template=<dir> Use a custom template directory for hooks and config

Examples

git init

Initialize repo in the current directory

git init -b main my-project

Create my-project/ with 'main' as the initial branch

git init --bare repo.git

Create a bare server-side repository

Gotcha

Running `git init` inside an existing repo is safe for history but will re-copy templated hooks and can overwrite customized hooks in .git/hooks. If you customized hooks, back them up first.

Related commands

← All Git commands · Git cheat sheet · Git rebase vs merge