Stop 03 · Git & GitHubTopics · 1/11

Git init

Part of the Backend Developer Roadmap

In short

Every backend you ever build starts as a folder of files. One command turns that plain folder into a project that remembers every change you make, forever.

`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 mascot opens a fresh, empty ledger notebook on a shop counter.

Think of it like this

The kirana shop's first ledger

When a kirana uncle opens a new shop, the first thing he does is buy a fresh khata book. Nothing is written yet, but from now on every sale has a place to go. git init is that fresh khata for your code.

Watch it happen

What git init creates

my-api/
src/
package.json
.git/
HEAD
objects/
refs/
config

1/5Before git init, my-api is just a normal folder with your code in it.

The big ideas

What you need to know

A repo is just .git

Delete the .git folder and your project forgets its history. Copy it and the history goes with it.

Set main as the default

Run git init -b main, or set init.defaultBranch once globally, so you don't end up with an old 'master' default.

Add .gitignore on day one

List node_modules and .env in .gitignore before your first commit, so secrets and huge folders never sneak in.

Tell Git who you are

Set user.name and user.email once. Every commit gets stamped with them, and GitHub uses the email to link commits to you.

See it in code

Walk through the code

bash
1mkdir my-api && cd my-api2git init -b main3 4git config --global user.name "Riya Sharma"5git config --global user.email "riya@example.com"6 7printf "node_modules/\n.env\n" > .gitignore8git status

1/3Make a folder and turn it into a repo whose first branch is called main.

git status is your best friend. Run it after every command until you can predict what it will say.

Save yourself the pain

Common mistakes

Oops

Running git init inside your home folder, so Git starts tracking your whole laptop.

Do this instead

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

Oops

Committing .env with your database password, then adding .gitignore later.

Do this instead

Create .gitignore before the first commit. Once a secret is committed, treat it as leaked and rotate it.

Your mission

Start your first backend repo

~10 min

Quick check

You delete the .git folder from your project. What happens?

Go deeper

  1. 1Run `git init` in a fresh folder and inspect the resulting `.git` directory.
  2. 2Add a `.gitignore` file before your very first commit.
  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