🌱 BasicsCommonly used

How to initialize a new Git repository

Create a new Git repository in the current directory or a new folder.

Initialize in current directory
git init

Creates a hidden .git folder in the current directory, turning it into a Git repository.

When to use: You already have a project folder and want to start tracking it with Git.

Initialize with a specific branch name
git init -b main

Creates a new repository with "main" as the default branch name instead of "master".

Requires Git 2.28+. GitHub uses "main" by default for new repos.

Initialize in a new folder
git init my-project

Creates a new directory called "my-project" and initializes a Git repo inside it.

← Back to Git Reference