Git & Version Control Fundamentals

Lesson 2 of 5

Your First Repository

A Git repository ("repo") is a project folder Git is tracking. Let's create one.

Initializing a repository

mkdir my-project
cd my-project
git init

git init creates a hidden .git folder, that's where Git stores the entire history of your project.

The three states of a file

StateMeaning
Untracked / ModifiedChanged on disk, not yet staged
StagedMarked to be included in the next commit
CommittedSaved permanently in the project's history
git status                   # see what's changed
git add app.js                # stage a specific file
git add .                     # stage everything
git commit -m "Add app.js"    # save the staged changes

Viewing history

git log
git log --oneline    # one line per commit, easier to scan

TIP

Commit often, in small, focused chunks. "Add login form" is a much more useful commit message than "stuff".

📝 First Repository Quiz

Passing score: 70%
  1. 1.Which command turns a folder into a Git repository?

  2. 2.Which command moves changes into the staging area?

  3. 3.git commit saves your staged changes to the project's permanent history.