Stop 05 · Git & GitHubTopics · 1/11

Git init

Part of the Frontend Developer Roadmap

In short

Ever named a file final_v2_REAL_final.html? Git fixes that for good. One command and your folder starts remembering every version you save.

`git init` turns a folder into a Git repository, creating the hidden `.git` directory that tracks every change you make from that point on. The repository stores metadata, objects, references, and configuration inside `.git`, while the working tree remains the files you actually edit.

The jaadu mascot opens a fresh, empty attendance register at a classroom desk.

Think of it like this

Opening a new attendance register

Before the register exists, nobody can mark anything. Once the class teacher opens it, every day gets recorded. git init opens that register for your folder. From then on, Git can record each change you choose to save.

Watch it happen

Your very first repo

You
Project folder
Staging area
.git repo

git init -b main

1/5Git creates the hidden .git folder. Your folder is now a repository, with an empty history.

The big ideas

What you need to know

A hidden .git folder

git init creates a .git folder inside your project. That's where Git keeps your whole history. Delete it and the history is gone.

Three places for your files

The working folder (what you edit), the staging area (what's ready to save) and the repository (saved snapshots).

.gitignore keeps junk out

List folders like node_modules and files like .env in .gitignore so Git never tracks them.

Name your first branch

Use git init -b main so your first branch is called main, which matches GitHub's default.

See it in code

Walk through the code

bash
1mkdir my-portfolio && cd my-portfolio2git init -b main3 4# Tell Git what to skip5echo "node_modules/" >> .gitignore6echo ".env" >> .gitignore7 8git status            # see what Git notices9git add .10git commit -m "Initial commit"

1/4Make a folder, move into it, and turn it into a Git repository with main as the first branch.

git status is your best friend. Run it whenever you're unsure, it tells you exactly which files are new, changed or staged.

Save yourself the pain

Common mistakes

Oops

Running git init in your home folder by mistake, so Git tracks your whole laptop.

Do this instead

Always cd into the project folder first. If it happened, delete that stray .git folder from home.

Oops

Adding .gitignore after node_modules is already committed.

Do this instead

Add .gitignore first. If it's too late, run git rm -r --cached node_modules and commit.

Your mission

Start tracking a project

~15 min

Quick check

You accidentally delete the .git folder inside your project. What do you lose?

Go deeper

  1. 1Run `git init` in a fresh folder and inspect the resulting `.git` directory. Validate your understanding by applying it in a small practical example.
  2. 2Add a `.gitignore` file before your very first commit. Test the result on both a successful path and an invalid or unexpected input.
  3. 3Learn the difference between initializing locally vs cloning an existing remote repo.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge