Track Changes Workshop
Practice the complete workflow of staging, reviewing, and committing changes. You'll also set up a proper .gitignore file.
Setup
Use an existing repository or create a new one:
bash1$ mkdir tracking-practice && cd tracking-practice2$ git init3$ echo "# Tracking Practice" > README.md4$ git add README.md5$ git commit -m "docs: add README"
Exercise 1: Create and Review Changes
Create a File
bash1$ cat <<'EOF' > app.js2function greet(name) {3 return `Hello, ${name}!`;4}56console.log(greet('World'));7EOF
Check Status
bash1$ git status -sb2## main3?? app.js
The ?? indicates an untracked file.
Stage and Review
bash1$ git add app.js23$ git status -sb4## main5A app.js67$ git diff --cached8diff --git a/app.js b/app.js9new file mode 10064410index 0000000..a1b2c3d11--- /dev/null12+++ b/app.js13@@ -0,0 +1,5 @@14+function greet(name) {15+ return `Hello, ${name}!`;16+}17+18+console.log(greet('World'));
Commit
bash1$ git commit -m "feat: add greeting function"2[main 2a3b4c5] feat: add greeting function3 1 file changed, 5 insertions(+)4 create mode 100644 app.js
Exercise 2: Set Up .gitignore
Create Common Ignores
bash1$ cat <<'EOF' > .gitignore2# Dependencies3node_modules/45# Build output6dist/78# Environment9.env10.env.local1112# Editor13.vscode/14.idea/1516# OS17.DS_Store18EOF
Test That It Works
Create files that should be ignored:
bash1$ mkdir node_modules2$ echo "fake dependency" > node_modules/test.txt3$ echo "SECRET_KEY=abc123" > .env45$ git status -sb6## main7?? .gitignore
Notice node_modules/ and .env don't appear—they're ignored!
Commit .gitignore
bash1$ git add .gitignore2$ git commit -m "chore: add gitignore"3[main 3b4c5d6] chore: add gitignore4 1 file changed, 15 insertions(+)5 create mode 100644 .gitignore
Exercise 3: Selective Staging with git add -p
Make Multiple Changes
bash1$ cat <<'EOF' > app.js2function greet(name) {3 return `Hello, ${name}!`;4}56function farewell(name) {7 return `Goodbye, ${name}!`;8}910console.log(greet('World'));11console.log(farewell('World'));12EOF
Use Interactive Staging
bash1$ git add -p app.js
Git will show each hunk (change) and ask what to do:
1@@ -2,6 +2,10 @@ function greet(name) {2 return `Hello, ${name}!`;3 }45+function farewell(name) {6+ return `Goodbye, ${name}!`;7+}8+9 console.log(greet('World'));10Stage this hunk [y,n,q,a,d,s,e,?]?
- Press
yto stage this hunk - Press
nto skip it - Press
sto split into smaller hunks
For this exercise, press y to stage everything.
Commit
bash1$ git commit -m "feat: add farewell function"2[main 4c5d6e7] feat: add farewell function3 1 file changed, 5 insertions(+)
Exercise 4: Inspect History
View Commit Log
bash1$ git log --oneline24c5d6e7 (HEAD -> main) feat: add farewell function33b4c5d6 chore: add gitignore42a3b4c5 feat: add greeting function51a2b3c4 docs: add README
View with Graph
bash1$ git log --oneline --graph --decorate2* 4c5d6e7 (HEAD -> main) feat: add farewell function3* 3b4c5d6 chore: add gitignore4* 2a3b4c5 feat: add greeting function5* 1a2b3c4 docs: add README
View Specific Commit
bash1$ git show 2a3b4c52commit 2a3b4c5...3Author: Your Name <you@example.com>4Date: Sun Nov 30 10:30:00 2025 +000056 feat: add greeting function78diff --git a/app.js b/app.js9new file mode 10064410...
Exercise 5: Modify and Review
Edit the README
bash1$ cat <<'EOF' >> README.md23## About45This is a practice repository for learning Git tracking.67## Usage89```bash10node app.js
EOF
12### Review Unstaged Changes34```bash5$ git diff6diff --git a/README.md b/README.md7index 1234567..abcdefg 1006448--- a/README.md9+++ b/README.md10@@ -1 +1,11 @@11 # Tracking Practice12+13+## About14+15+This is a practice repository for learning Git tracking.16+17+## Usage18+19+```bash20+node app.js21+```
Stage and Review Staged
bash1$ git add README.md2$ git diff --cached
Commit
bash1$ git commit -m "docs: add about and usage sections"2[main 5d6e7f8] docs: add about and usage sections3 1 file changed, 10 insertions(+)
Final Check
Review your complete history:
bash1$ git log --oneline25d6e7f8 (HEAD -> main) docs: add about and usage sections34c5d6e7 feat: add farewell function43b4c5d6 chore: add gitignore52a3b4c5 feat: add greeting function61a2b3c4 docs: add README
Verify ignored files:
bash1$ git status --ignored --short2!! .env3!! node_modules/
Checklist
- Created and committed multiple files
-
.gitignoreis working (ignoringnode_modules/and.env) - Used
git add -pfor selective staging - Reviewed changes with
git diffandgit diff --cached - History shows clean, descriptive commits
Cleanup
bash1$ cd ..2$ rm -rf tracking-practice
Key Takeaway
You've practiced the core Git workflow: status → add → diff → commit → log. This cycle repeats throughout your development work. Make it second nature.