git init

The command that turns the current directory into a Git repository by creating the hidden .git directory.

In more detail

After git init the repository has no commits yet: .git/HEAD names a branch, such as main, that will be created by your first commit. Running it again in the same place is safe and prints Reinitialized existing Git repository. Running it inside another repository creates a nested repository, which is almost always a mistake.

Example

mkdir my-project && cd my-project && git init

Related terms

Taught in

References

Certification courses