Lesson

Git Get Started

10 min reading
Free Course

Git Get Started: Initializing Your First Repository

Running git init turns any regular folder on your computer into a Git repository ready to track file history. Git creates a hidden .git directory inside your project root without altering any of your existing source files.

Creating a Project and Running git init

Start by creating a clean project folder for a sample website, moving into it, and initializing Git:

mkdir starter-site
cd starter-site
git init

Git prints Initialized empty Git repository in .../starter-site/.git/. If you configured init.defaultBranch to main, your initial unborn branch is already main. If you are on an older setup that defaults to another name, rename it right away:

git branch -M main

What the Hidden .git Folder Stores

List hidden files in your terminal to confirm the .git directory exists:

ls -la

Inside .git, Git stores object snapshots (blobs, trees, and commits), branch pointers under refs/, the HEAD pointer to your active branch, and local repository settings in config. Because every snapshot lives inside .git, deleting that single hidden folder removes all Git history while leaving your working files untouched.

Checking Repository Status

Right after initialization, run git status to confirm Git is active and inspect the current branch:

git status

Git reports On branch main and No commits yet, confirming your workspace is clean and ready for your first files.

Common Mistakes When Initializing Git

Never run git init inside your operating system home folder (~ or C:\Users\YourName) or Desktop directory. Doing so tells Git to track thousands of unrelated personal files and slows down your terminal prompt.

Also avoid initializing a Git repository inside an existing Git repository unless you intentionally want a submodule. Always check git status before running git init to verify you are not already inside a tracked parent folder.

Frequently Asked Questions

What happens if I run git init in a folder that already has code?

It is completely safe. git init only adds the hidden .git folder and marks your existing files as untracked until you choose which ones to stage with git add.

Is running git init twice harmful?

No. Running git init in an already initialized repository reinitializes templates without overwriting your existing commits, branches, or modified working files.

When should I use git init versus git clone?

Use git init when starting a brand-new local project from scratch. Use git clone when copying an existing project from GitHub or another remote server.

Save Your Progress

Unlock Your
Full Potential.

Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.

Quick Access With

Enterprise-Grade Security Protocol
Git Topic Hub

Stuck on this lesson?

Join our community of senior developers.

Ask in Forum