🏠 Home / Hub

🔶 Git Lesson 01 — Basics (Init, Add, Commit)

← Back to Git Menu  |  🏠 Hub

1. Git ဆိုတာ ဘာလဲ

Git = Distributed Version Control System
Linus Torvalds (Linux creator) က 2005 မှာ create

📸 Code changes ကို snapshot (commit) အဖြစ် save
⏪ မှားရင် previous version ကို restore
🤝 Team members တွေ တပြိုင်နက် work လုပ်နိုင်
🌿 Branch = feature ကို isolate ပြီး develop
Without GitWith Git
Backupproject_v1, project_v2, final...git commit -m "version"
UndoDelete file ← gone!git revert / reset
CollaborationEmail files back and forthgit push/pull/merge
HistoryNo recordgit log — full history

2. First-Time Setup

# 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

3. git init — Start a Repository

# 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

4. git add & git commit — Save Changes

# 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
💡 Commit early, commit often — small commits = easier to understand + revert if needed

5. Undo Changes

# 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 →

📌 Study Checklist