Rana Maninder Singh
Lesson 2 of 8Git & GitHub

Install Git & Your First Repository

Lesson opener

In one line: Install Git on Windows, Mac, or Linux.

Why it matters: This shows up at work when you need to install Git on Windows, Mac, or Linux.

Before this lesson: Why Git exists

Before you start

ResourceLink
PreviousWhy Git exists
NextHistory, diff & undo
Time~45 minutes

What you will learn

  • Install Git on Windows, Mac, or Linux
  • Configure your identity (required for commits)
  • git init, git status, git add, git commit
  • .gitignore — never commit secrets or junk
  • Verify every step with expected output

Section 1 — Install Git

Windows

  1. Download Git for Windows: https://git-scm.com/download/win
  2. Run installer — defaults are fine for learners
  3. Verify in PowerShell or Git Bash:
git --version

Expected output (example):

git version 2.47.0.windows.1

Mac

# Option A — Xcode Command Line Tools (often already installed)
xcode-select --install

# Option B — Homebrew
brew install git

git --version

Linux (Debian/Ubuntu)

sudo apt update && sudo apt install -y git
git --version

Section 2 — One-time configuration

Git stamps every commit with your name and email:

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

Use the same email as your GitHub account later (helps link commits to your profile).

Verify:

git config --global --list

Set default branch name to main (modern standard):

git config --global init.defaultBranch main

Optional but recommended (2026):

git config --global pull.rebase false
git config --global core.autocrlf true

On Mac/Linux use core.autocrlf input instead of true.


Section 3 — Create your first repo

mkdir my-first-repo
cd my-first-repo
git init

Expected:

Initialized empty Git repository in .../my-first-repo/.git/

The hidden .git folder is the repository — do not delete it.

Create a file:

echo "# My First Repo" > README.md
git status

Expected: README.md listed under Untracked files (red).


Section 4 — Stage and commit

git add README.md
git status

Expected: README.md under Changes to be committed (green).

git commit -m "Add README with project title"

Expected: [main (root-commit) abc1234] Add README with project title

View history:

git log --oneline

Section 5 — Commit messages that work

BadGood
fixFix divide-by-zero in sales report
updatesAdd March CSV to data folder
asdfasdfRemove hardcoded API key from config

Format: imperative mood — "Add feature" not "Added feature"


Section 6 — .gitignore (non-negotiable)

Create .gitignore in repo root:

# Secrets — NEVER commit
.env
*.pem
credentials.json

# Python
.venv/
__pycache__/
*.pyc

# Node / React Native
node_modules/

# OS junk
.DS_Store
Thumbs.db

# Large outputs
*.pbix
outputs/*.tmp
git add .gitignore
git commit -m "Add gitignore for secrets and build artifacts"

If you already committed a secret: rotating the key is not enough — it's in history. See git3 and GitHub's secret scanning docs.


Section 7 — Expected UI (terminal workflow)


Practice

Capstone mini-task:

  1. Create practice-notes.txt with three things you learned today
  2. git add and git commit with a clear message
  3. Edit the file — run git status and confirm Git sees the change as modified

Checklist

  • [ ] git --version works
  • [ ] user.name and user.email configured
  • [ ] Created repo with at least 2 commits
  • [ ] .gitignore excludes .env and node_modules/

Teacher walkthrough: first honest commit

All figures illustrative.

Step 1 — Install verify. git --version; set user.name / user.email as taught.

Step 2 — git init in the project folder (not your entire home directory).

Step 3 — .gitignore before first add (secrets, node_modules, outputs).

Step 4 — add → status → commit with a message that states why.

Failure example: committed node_modules and a key

Symptom: Repo huge; key rotated in panic; host scanners alert.

Diagnosis: No .gitignore; blind git add ..

Correction: Ignore patterns first; remove secrets from history if needed (follow host docs); rotate keys.

Validation: git status clean; tracked files show no .env.

Guided practice

Order these: commit, init, add, write .gitignore.

Complete solution: init → write .gitignore → add → commit.

Independent practice

Acceptance criteria:

Common mistakes

  1. git init in the wrong directory.
  2. Empty or joke commit messages on shared repos.
  3. Force-adding ignored secrets.

What's next

History, diff & undo — read the past and recover from mistakes safely.