Git & GitHub Essentials
If you skip this section, you'll create noise instead of value. Version control is the universal language of open source.
Why This Matters
35% of PR rejections come from poor Git practices: messy commits, merge conflicts, wrong branches.
What You'll Learn
| Topic | Why It Matters | Time |
|---|---|---|
| Git Basics | Foundation for everything | 30 min |
| Branching Strategy | Organize your work | 20 min |
| Commit Messages | Communication through code | 15 min |
| Syncing Fork | Stay up-to-date | 15 min |
| Merge Conflicts | Handle the inevitable | 25 min |
| Rewriting History | Clean up your work | 20 min |
| Force Push | Know the dangers | 10 min |
The Git Mental Model
Key Concepts Overview
Repository Structure
your-project/
├── .git/ # Git metadata (don't touch!)
│ ├── config # Remote URLs, settings
│ ├── HEAD # Current branch pointer
│ ├── objects/ # All commits, files
│ └── refs/ # Branch pointers
├── src/ # Your code
└── README.mdThe Three States of Files
| State | Meaning | Command to Move |
|---|---|---|
| Untracked | Git doesn't know about it | git add |
| Staged | Ready to be committed | git commit |
| Committed | Saved in history | (edit file) |
| Modified | Changed since last commit | git add |
Essential Commands Cheat Sheet
Daily Workflow
git status # What's changed?
git add . # Stage everything
git commit -m "msg" # Save changes
git push # Upload to GitHub
git pull # Download updatesBranching
git branch # List branches
git checkout -b name # Create & switch
git checkout main # Switch to main
git merge branch # Merge branchSyncing
git fetch upstream # Get upstream changes
git merge upstream/main # Merge them
git push origin main # Update your forkCommon Mistakes to Avoid
❌ Don't Do This
# Committing to main directly
git checkout main
git commit -m "my feature" # ❌ NO!
# Force pushing to shared branches
git push --force origin main # ❌ DANGEROUS!
# Giant commits with everything
git add .
git commit -m "stuff" # ❌ Meaningless✅ Do This Instead
# Work on feature branches
git checkout -b feature/add-login
git commit -m "feat: add login form" # ✅
# Only force push YOUR feature branches
git push --force origin feature/my-branch # ✅ OK
# Atomic, meaningful commits
git add src/login.js
git commit -m "feat(auth): add login form validation" # ✅Self-Assessment
Before proceeding, you should know:
- How to clone a repository
- How to create a branch
- How to commit changes
- How to push to remote
- What a merge conflict is
Score yourself:
- 5/5 → Skip to Syncing Fork
- 3-4/5 → Start with Git Basics
- 0-2/5 → Read everything carefully
Tools to Help
GUI Clients
| Tool | Platform | Best For |
|---|---|---|
| GitHub Desktop | Win/Mac | Beginners |
| GitKraken | All | Visual learners |
| VS Code Git | All | Editor integration |
| Sourcetree | Win/Mac | Advanced users |
Terminal Enhancements
# Oh My Zsh git plugin
alias gs="git status"
alias gc="git commit"
alias gp="git push"
alias gl="git log --oneline"Learning Path
Estimated total time: ~2.5 hours
Quick Reference Card
Creating a PR Workflow
Next Steps
Ready to dive in? Start with the first topic:
Pro Tip: Bookmark this page. You'll reference these commands hundreds of times in your open source journey.