Git/
Lesson

You understand what Git is and why it matters. Now let's get your hands dirty and actually set up your first repositoryWhat is repository?A project folder tracked by Git that stores your files along with the complete history of every change, inside a hidden .git directory.. By the end of this lesson, you'll have a fully functional Git repo ready for your code.

Turning a folder into a repositoryWhat is repository?A project folder tracked by Git that stores your files along with the complete history of every change, inside a hidden .git directory.

Here's the beautiful thing about Git: it doesn't care what kind of project you have. A Python script, a React app, a novel written in Markdown, Git handles them all the same way.

To start tracking any folder, you just run one command:

# Navigate to your project folder
cd my-awesome-project

# Initialize Git
git init

You'll see confirmation like this:

Initialized empty Git repository in /home/you/my-awesome-project/.git/

That's it. Your folder is now a Git repository.

What just happened?

Git created a hidden folder called .git in your project directory. This isn't just a simple folder, it's a complete database containing:

  • Every commitWhat is commit?A permanent snapshot of your staged changes saved in Git's history, identified by a unique hash and accompanied by a message describing what changed. you've ever made (or will make)
  • All branch information and configuration
  • The staging areaWhat is staging area?A holding zone in Git where you place changes you want to include in your next commit, letting you select exactly which modifications to save.'s current state
  • Compressed snapshots of your files
Warning, never touch the .git folder: You might be tempted to peek inside or even delete it if you're cleaning up space. Don't. This folder IS your repository. Delete it, and you delete your entire project history. If you need to stop using Git on a project, just stop running Git commands, leave that folder alone.
02

Verifying everything worked

How do you know Git is actually watching your folder? Run the status command:

git status

If Git is initialized, you'll see something like:

On branch main

No commits yet

nothing to commit (create/copy files and use "git add" to track)

This tells you three important things:

  1. You're on the default branch (usually called main)
  2. You haven't made any commits yet
  3. Git is ready and waiting for you to add files

If you see "fatal: not a git repositoryWhat is repository?A project folder tracked by Git that stores your files along with the complete history of every change, inside a hidden .git directory.", Git isn't initialized. Run git init again.

03

Setting up your first .gitignore

Before you start adding files, there's one crucial step every project needs: creating a .gitignore file. This tells Git which files to completely ignore.

Why you need this

Not everything belongs in version control. Some files are:

  • Auto-generated (build outputs, compiled code), they'll be recreated
  • Environment-specific (your personal settings, local database), they won't work on other machines
  • Sensitive (APIWhat is api?A set of rules that lets one program talk to another, usually over the internet, by sending requests and getting responses. keys, passwords), sharing these is a security disaster

AI pitfall
When AI generates a project scaffold, it almost never creates a .gitignore file. If you run git add . without one, you'll commit node_modules/ (hundreds of megabytes), .env files (your secrets), and build artifacts. Always create .gitignore before your first git add.

Common patterns to ignore

Here's a basic .gitignore for a Node.js project:

# Create the file
touch .gitignore

# Add common patterns
echo "node_modules/" >> .gitignore
echo ".env" >> .gitignore
echo "dist/" >> .gitignore
echo "*.log" >> .gitignore
PatternWhat it ignoresWhy
node_modules/All npm packagesThese are installed via npm install and can be huge
.envEnvironment variablesContains secrets like API keys
dist/ or build/Compiled outputGenerated automatically from source
*.logLog filesConstantly changing, not useful for history
.DS_StoremacOS system filesJust clutter for other operating systems
Pro tip
GitHub maintains excellent starter .gitignore templates for every language. Search "github gitignore [your-language]" and copy the appropriate file. It's much better than building one from scratch.
04

Your initialization checklist

When starting a new project, here's the exact sequence to follow:

# 1. Create your project folder
mkdir my-new-project
cd my-new-project

# 2. Initialize Git
git init

# 3. Create .gitignore (copy from GitHub templates)
curl -o .gitignore https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore

# 4. Verify it worked
git status

At this point, you're ready to start coding. When you create files, Git will notice them as "untracked." That's the subject of our next lesson.

05

Quick reference

CommandWhat it doesWhen to use it
git initInitialize a new repoOnce per project
git statusSee repo stateConstantly, your best friend
touch .gitignoreCreate ignore fileBefore first commit
git init in existing repoDoes nothing harmfulSafe to run again
javascript
# Initialize a new repository
git init

# Check the status of your repository
git status

# Create a .gitignore file
echo "*.log" > .gitignore
echo "node_modules/" >> .gitignore
echo ".env" >> .gitignore