Skip to content
Latchkey

git init: Usage, Options & Common CI Errors

git init turns a directory into a Git repository by creating the .git folder.

Use git init to start version control in a fresh directory or to set up a bare repo for pushing to.

What it does

git init creates a new .git subdirectory containing all the repository metadata. Running it in an existing repo is safe and only reinitializes; it does not overwrite your work.

Common usage

Terminal
git init
git init --initial-branch=main my-project
git init --bare repo.git

Options

FlagWhat it does
--bareCreate a bare repo (no working tree) for serving
--initial-branch=<name> / -bSet the first branch name (default historically "master")
--template=<dir>Use a custom template directory
--quiet / -qSuppress output

Common errors in CI

A common surprise is the default branch name: older Git defaults to "master" while hosts expect "main". Set it explicitly with git init -b main, or configure git config --global init.defaultBranch main so scripts are deterministic across runner images.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →