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
| Resource | Link |
|---|---|
| Previous | Why Git exists |
| Next | History, 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
- Download Git for Windows: https://git-scm.com/download/win
- Run installer — defaults are fine for learners
- Verify in PowerShell or Git Bash:
git --versionExpected output (example):
git version 2.47.0.windows.1Mac
# Option A — Xcode Command Line Tools (often already installed)
xcode-select --install
# Option B — Homebrew
brew install git
git --versionLinux (Debian/Ubuntu)
sudo apt update && sudo apt install -y git
git --versionSection 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 --listSet default branch name to main (modern standard):
git config --global init.defaultBranch mainOptional but recommended (2026):
git config --global pull.rebase false
git config --global core.autocrlf trueOn Mac/Linux use core.autocrlf input instead of true.
Section 3 — Create your first repo
mkdir my-first-repo
cd my-first-repo
git initExpected:
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 statusExpected: README.md listed under Untracked files (red).
Section 4 — Stage and commit
git add README.md
git statusExpected: 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 --onelineSection 5 — Commit messages that work
| Bad | Good |
|---|---|
fix | Fix divide-by-zero in sales report |
updates | Add March CSV to data folder |
asdfasdf | Remove 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/*.tmpgit 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:
- Create
practice-notes.txtwith three things you learned today git addandgit commitwith a clear message- Edit the file — run
git statusand confirm Git sees the change as modified
Checklist
- [ ]
git --versionworks - [ ]
user.nameanduser.emailconfigured - [ ] Created repo with at least 2 commits
- [ ]
.gitignoreexcludes.envandnode_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:
- Repo initialised in the correct folder.
.gitignoreexcludes at least secrets and dependencies.- First commit visible in
git log. git statusunderstood (clean vs staged).
Common mistakes
git initin the wrong directory.- Empty or joke commit messages on shared repos.
- Force-adding ignored secrets.
What's next
History, diff & undo — read the past and recover from mistakes safely.