Git Tutorial

1. What is Git really? (Super simple analogy)

Imagine you’re writing a very important story (a novel).

  • Without Git → You make copies: story_v1.docx story_v2_final.docx story_v2_final_really.docx story_v2_final_23-01-2026.docx → Chaos after 2 weeks
  • With Git → You have one single story file, but Git secretly keeps perfect snapshots (called commits) every time you say “this part is good now”.

You can:

  • Go back to any previous version in 2 seconds
  • See exactly what changed between versions
  • Have multiple people work on the same story without overwriting each other
  • Try risky ideas safely in a separate room (branch) and throw them away if bad

Git = time machine + safety net + team collaboration tool for files (mostly code).

Git ≠ GitHub Git = the tool on your computer GitHub = popular online storage + collaboration website for Git repositories

2. First things first – Installation (2026 edition)

Open your terminal / command prompt / PowerShell:

Check if Git is already installed:

Bash

If you see something like git version 2.4x.x, great! Skip to step 3.

Otherwise:

  • Windows → https://git-scm.com/download/win → install → choose Use Git from Git Bash and Command Prompt
  • macOS → brew install git (if you have Homebrew) or download from site
  • Linux (Ubuntu) → sudo apt update && sudo apt install git

After install, set your identity (very important – appears in commits):

Bash

Check:

Bash

3. Our First Project – Hands-on from scratch

Let’s create a tiny project.

  1. Create folder and go inside
Bash
  1. Tell Git: “Start tracking this folder”
Bash

You’ll see: Initialized empty Git repository in …/.git/

Now there’s a hidden .git folder — that’s your time machine.

  1. Create first file

Create index.html (you can use VS Code, Notepad, whatever)

HTML
  1. Tell Git: “Hey, watch this file”
Bash

You’ll see red: index.html is untracked

Now add it to staging area (index):

Bash

git status now shows green.

Staging = “I want to include these changes in my next snapshot”

  1. Take first snapshot (commit)
Bash

You’ll see something like:

text

Congratulations! 🎉 You just made your first commit.

4. Everyday Workflow – The sacred 4 steps

You work → stage → commit → (later) push

Let’s make changes:

Add one more todo in index.html:

HTML

Now:

Bash

Do few more changes:

  • Change title to <h1>My Awesome Todo List 2026</h1>
  • Add one more <li>Walk 30 mins</li>
Bash

Now check history:

Bash

You should see something like:

text

Beautiful timeline!

5. Undo / Time Travel – Most useful beginner skills

Oops! I messed up the title!

See last commit:

Bash

Go back one version:

Bash

Want to permanently undo last commit but keep changes in working directory?

Bash

Want to completely throw away last commit?

Bash

Made mess in working directory (not committed yet)?

Bash

6. Branches – Why they are awesome

Main = stable version (usually called main now, not master)

You want to try new feature without breaking main.

Bash

Now you’re on new branch. Change index.html – add dark mode class or whatever.

HTML

Commit:

Bash

Switch back:

Bash

→ Dark mode disappeared! (safe)

Like it? Merge:

Bash

Don’t like? Delete branch:

Bash

7. Connect to GitHub (remote)

  1. Go to github.com → New repository Name: my-todo-app Public / Private → create (do not check “Add README”)
  2. Link your local repo:
Bash
  1. Send your work:
Bash

Now your code lives online too!

From now on just:

Bash

Quick Summary Table – Your First-day Cheat Sheet

Action Command What it does
Start tracking folder git init Creates .git folder
See what’s happening git status Most used command!
Add file to staging git add file.txt / git add . Prepare for commit
Save snapshot git commit -m “message” Creates version
See history git log –oneline Beautiful list
Create & switch branch git checkout -b name Safe experiment space
Merge branch git checkout main git merge name Combine changes
Send to GitHub git push After first push -u
Get latest from GitHub git pull Very important when collaborating

Practice this flow 5–10 times on a dummy folder and you’ll never forget it.

Any command confusing? Which part you want to go deeper — branching, resolving conflicts, .gitignore, pull requests, or something else?

Just tell me — we’ll continue the class! 🚀