Synopsis
Description
Thegit init command creates an empty Git repository - basically a .git directory with subdirectories for objects, refs/heads, refs/tags, and template files. An initial branch without any commits will be created.
Running
git init in an existing repository is safe. It will not overwrite things that are already there.Common Usage
Create a new repository
Initialize a new Git repository in the current directory:This creates a
.git subdirectory in the current directory.Options
-q, --quiet
-q, --quiet
Only print error and warning messages; all other output will be suppressed.
--bare
--bare
Create a bare repository. If
GIT_DIR environment is not set, it is set to the current working directory.Bare repositories are typically used as centralized repositories on servers.
--object-format=<format>
--object-format=<format>
Specify the object format (hash algorithm) for the repository. Valid values are
sha1 and sha256. Default is sha1.--ref-format=<format>
--ref-format=<format>
Specify the reference storage format for the repository.
-b <branch-name>, --initial-branch=<branch-name>
-b <branch-name>, --initial-branch=<branch-name>
Use the specified name for the initial branch in the newly created repository.
--template=<template-directory>
--template=<template-directory>
Specify the directory from which templates will be used.
--separate-git-dir=<git-dir>
--separate-git-dir=<git-dir>
Instead of initializing the repository in
./.git/, create a text file there containing the path to the actual repository.--shared[=<permissions>]
--shared[=<permissions>]
Examples
Create a new project
Initialize with custom branch name
Create a shared repository
Related Commands
- git clone - Clone a repository into a new directory
- git add - Add file contents to the index
- git commit - Record changes to the repository
