| Without Git | With Git | |
|---|---|---|
| Backup | project_v1, project_v2, final... | git commit -m "version" |
| Undo | Delete file ← gone! | git revert / reset |
| Collaboration | Email files back and forth | git push/pull/merge |
| History | No record | git log — full history |
# Install: git-scm.com (Windows), or "brew install git" (Mac) # Verify git --version # git version 2.43.0 # Identity setup (REQUIRED — one time only) git config --global user.name "Ko Ko" git config --global user.email "ko@example.com" # Default branch name (recommended: main) git config --global init.defaultBranch main # Default editor git config --global core.editor "code --wait" # VS Code # View config git config --list
# Navigate to project folder cd C:\projects\myapp # Initialize git repository git init # Creates hidden .git/ folder — don't touch this! # Check status git status # Shows: untracked files, staged changes, current branch # .gitignore — tell git what to IGNORE # Create file: .gitignore node_modules/ .env .env.local dist/ *.log .DS_Store # Mac OS file Thumbs.db # Windows file # After creating .gitignore git status # node_modules won't show as untracked anymore
# Working Directory → Staging Area → Repository # Stage specific files git add index.html git add src/app.js git add css/style.css # Stage all changes git add . # See what's staged git status git diff --staged # view exact changes before commit # Commit — save snapshot git commit -m "add homepage layout" # Commit message best practices: # ✅ "add login form validation" # ✅ "fix navigation menu on mobile" # ✅ "update package dependencies" # ❌ "fix bug" ← too vague # ❌ "changes" ← meaningless # Shortcut: add + commit in one (tracked files only) git commit -am "update styles" # View commit history git log git log --oneline # compact view git log --oneline --graph # branch visualization git log --oneline -10 # last 10 commits git log --author="Ko Ko" # by author
# Discard changes in working directory (CAREFUL — not recoverable) git restore filename.html # undo unstaged changes git restore . # undo all unstaged changes # Unstage (remove from staging, keep changes) git restore --staged filename.html # Amend last commit (fix message or add forgotten file) git add forgotten_file.html git commit --amend -m "better message" # ⚠️ Only on LOCAL commits not pushed yet! # View what changed git diff # unstaged changes git diff --staged # staged changes git diff HEAD~1 # compare with previous commit # git show — view a commit git show abc1234 # commit hash # Restore file from previous commit git restore --source=HEAD~2 filename.html # from 2 commits ago
← Git Menu | Next: Git 02 → Branches →