Git 2 reference · Basics

git init Command (Git)

Create a new Git repository in a directory, optionally naming the first branch, ready for the first commit.

Git 2

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

git init [-b BRANCH] [DIRECTORY]

Parameters

ParameterDescription
-b NAME Name of the initial branch (e.g. main).
--bare A repository without a working tree (for servers/remotes).

Examples

A new repository
git init -q -b main shop
ls -A shop
git -C shop branch --show-current

Output

.git
main

Run this on your computer — see “Get Started” for setup.

A bare repository for use as a remote
git init -q --bare remote.git
ls remote.git | head -4

Output

HEAD
branches
config
description

Run this on your computer — see “Get Started” for setup.

Was this page helpful?