Git & GitHub
Overview

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

TopicWhy It MattersTime
Git BasicsFoundation for everything30 min
Branching StrategyOrganize your work20 min
Commit MessagesCommunication through code15 min
Syncing ForkStay up-to-date15 min
Merge ConflictsHandle the inevitable25 min
Rewriting HistoryClean up your work20 min
Force PushKnow the dangers10 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.md

The Three States of Files

StateMeaningCommand to Move
UntrackedGit doesn't know about itgit add
StagedReady to be committedgit commit
CommittedSaved in history(edit file)
ModifiedChanged since last commitgit 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 updates

Branching

git branch              # List branches
git checkout -b name    # Create & switch
git checkout main       # Switch to main
git merge branch        # Merge branch

Syncing

git fetch upstream      # Get upstream changes
git merge upstream/main # Merge them
git push origin main    # Update your fork

Common 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:

Tools to Help

GUI Clients

ToolPlatformBest For
GitHub DesktopWin/MacBeginners
GitKrakenAllVisual learners
VS Code GitAllEditor integration
SourcetreeWin/MacAdvanced 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:

➡️ Git Basics You Must Know →


Pro Tip: Bookmark this page. You'll reference these commands hundreds of times in your open source journey.