A Comprehensive Guide for Web & Mobile Developers
⏱️ 15 minute read
Git's three-tree architecture (Working Directory, Staging Area, Repository)
A system that records changes to files over time, allowing you to:
| Type | Description | Example | When to Use |
|---|---|---|---|
| Local | Tracks changes on a single machine | RCS, SCCS | Individual projects with no need for collaboration |
| Centralized | Single server hosts all versions | SVN, CVS | Small teams with centralized infrastructure |
| Distributed | Every user has a full repository copy | Git, Mercurial | Modern development (teams, open source, etc.) |
Git file lifecycle - from untracked to committed
git init
git clone https://github.com/user/repo.git
git status
git add index.html styles.css
git add .
git commit -m "Add user login functionality"
Commit Message Guidelines:
git branch
git checkout -b feature/login
git checkout main
git merge feature/login
Git 2.23+ introduced git switch and git restore:
git switch -c new-feature # Create and switch git switch main # Switch branches
git reset --soft HEAD~1
git checkout -- index.html
git revert a1b2c3d
git reset --hard HEAD~3
This will permanently delete the last 3 commits and all their changes. Use with extreme caution!
git log --oneline --graph --all
git show abc123
git diff main..feature
git clone https://github.com/your-username/repo.git
git remote add upstream https://github.com/original-owner/repo.git
git fetch upstream
git merge upstream/main
good-first-issue labeled tasksgit checkout -b your-username
git push origin your-username
Important: Your branch name must exactly match your GitHub username for verification.
.gitignore to exclude unnecessary files| Strategy | Use Case |
|---|---|
| Feature Branches | New functionality (e.g., feat/user-auth) |
| Hotfix Branches | Critical bug fixes |
| Git Flow | Complex projects with versions |
Automate testing with GitHub Actions:
name: Node.js CI
on: [push]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: npm install && npm test
Pro Tip: Maintain a DEVLOG.md to document your learning journey!