Git init: initialize a Git repository
Every Git project starts with git init. This command transforms a simple folder into a version-controlled repository. Learn what it does, what it creates, and how to get started.
What is git init?
git init initializes a new Git repository in the current directory. Concretely, it creates a hidden .git/ folder that contains all the structure needed for version control.
It's the first command you run when starting a new project. After git init, you can start adding files and creating commits.
If you're joining an existing project, use git clone instead, which runs git init automatically.
What git init creates
.git/objects/Stores commits, trees, and compressed files
.git/refs/References for branches and tags
.git/HEADPoints to the current branch
.git/configLocal repository configuration
Git init in practice
Initialize a repository and make your first commit.
Initialize the repository
First commit
git init vs git clone
git init
Creates an empty repository from scratch. No history, no files. You make the first commit yourself.
git clone
Copies an existing repository from a remote server with its full history, branches, and tags.
Common mistakes with git init
Initializing in the wrong folder
Check that you're in the right directory with pwd before running git init. A repository initialized in ~ (home) would track your entire personal folder.
Nested Git repositories
Never run git init inside a folder that is already part of a Git repository. This creates nested repositories that cause unpredictable behavior.
Forgetting the .gitignore
Create a .gitignore file before your first commit to exclude node_modules, .env, build files, etc. It's much easier than removing them later.
Part of the Git Basics guide
GitQuest is created by Anaïs (nouvelle fenêtre), web developer and head of education, specializing in tech training and digital accessibility.
Questions about git init
Ready to initialize your first repository?
GitQuest guides you step by step through creating your first Git project.
Get started now