Git Init

What

A Git repository (or “repo”) represents a single project tracked by version control. It is essentially a standard directory on your filesystem that contains your project files, plus a hidden .git directory at its root.

How

To turn any existing or new directory into a Git repository, you navigate to the directory in your terminal and run the git init command:

# Create a new project directory
mkdir my-project
cd my-project

# Initialize a new Git repository
git init

Running this command creates a hidden directory named .git within your project root:

# List all files, including hidden directories
ls -la
# Output includes: .git/

Why

The hidden .git directory is where Git stores all of its internal tracking, configuration files, commit histories, refs, hooks, and object databases. As long as this folder exists, Git can track modifications to any files within the project. If you delete this folder, you remove all version control history, transforming the project back into a plain, untracked directory.

Summary

Use git init to initialize a new repository, which creates the hidden .git database directory responsible for storing your project’s complete version history.