Lesson 2 — Git & GitHub Journey

Understanding File Changes in Git
Today you’ll learn:
git diff
staging vs unstaging
restoring files
.gitignore
These are daily-use Git skills.
1. Modify Existing File
Change your file:
touch notes.txt
echo "New line added" >> notes.txt
Now check:
git status
You’ll see:
modified: notes.txt
Git detected changes.
2. View Exact Changes
Use:
git diff
This shows:
old content
new content
Example:
+ New line added
Meaning:
+ added line
- removed line
Important
git diff shows:
Working Directory vs Staging Area
3. Stage Changes
git add notes.txt
Now:
git status
4. Difference After Staging
You may see nothing.
Why?
Because changes are already staged.
Now use:
git diff --staged
This shows:
Staging Area vs Last Commit
VERY important: Core Git Understanding
git diff
↓
unstaged changes
git diff --staged
↓
staged changes
5. Unstage File
Suppose you accidentally staged something. Use:
git restore --staged notes.txt
Now file becomes unstaged again.
Check:
git status
6. Restore File (Discard Changes)
Suppose you made bad edits.
Use: git restore notes.txt
This removes uncommitted changes.
git restore <file>
# This removes uncommitted changes.
⚠ Dangerous: Changes are lost permanently.
Real Meaning: git restore file
Means: "Bring file back from last commit"
7. Create Unwanted Files
Example:
touch debug.log
touch secret.env
These should NOT go to Git.
8. Use .gitignore
Create:
touch .gitignore
Add:
*.log
*.env
node_modules/
dist/
Now Git ignores them.
Check: git status
Ignored files disappear.
Why .gitignore Matters
Never upload:
secrets
passwords
API keys
cache files
build folders
Very important in real projects.
Common .gitignore Examples
Node.js
node_modules/
.env
dist/
Python
__pycache__/
venv/
.env



