Development Tools
GitHub
GitHub is a website where developers store and share their code. Think of it like Google Drive, but specifically designed for code projects.
What Problem Does It Solve?
Imagine you're writing a paper and want to save different versions. You might save files like "essay_v1.doc", "essay_v2.doc", "essay_final.doc". GitHub does this automatically for code, letting you track every change and go back to any previous version.
The Basics
- Repository (Repo) — A folder for your project that lives on GitHub
- Commit — A save point with a message describing what you changed
- Push — Upload your changes to GitHub
- Pull — Download the latest changes from GitHub
- Clone — Download a complete copy of a repository to your computer
The Essential Workflow
The daily workflow is simple:
- Make changes to your code
- Save those changes with a commit message
- Push to GitHub so it's backed up in the cloud
Key Commands
git add .— Stage all your changesgit commit -m "your message"— Save with a descriptiongit push— Upload to GitHubgit pull— Download latest changes
Why It Matters
Almost every software company uses GitHub or something similar. Learning it is essential for any developer, and it's free to use for personal projects.
Beyond basic version control, GitHub is a full collaboration platform. Understanding branches, pull requests, and GitHub's ecosystem unlocks team workflows and open-source contribution.
Branching Strategy
Branches let you work on features without affecting the main codebase. The standard flow:
- main/master — Production-ready code, always stable
- feature branches — Where you build new features (
feature/user-auth) - hotfix branches — Quick fixes for production bugs
git checkout -b feature/new-dashboard # Create and switch to new branch git push -u origin feature/new-dashboard # Push branch to GitHub git checkout main # Switch back to main git merge feature/new-dashboard # Merge feature into main
Pull Requests (PRs)
PRs are how code gets reviewed before merging. They enable:
- Code review and discussion
- Automated testing (CI/CD)
- Documentation of why changes were made
- Protected branches that require approval
GitHub Actions (CI/CD)
Automate testing, building, and deployment with workflow files:
# .github/workflows/test.yml
name: Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: npm install
- run: npm test
Useful Commands
git stash— Temporarily save uncommitted changesgit log --oneline— Compact commit historygit diff— See what's changedgit blame file.js— See who wrote each linegit revert <commit>— Undo a specific commit safely
GitHub Features
- Issues — Bug tracking and feature requests
- Projects — Kanban boards for project management
- Discussions — Community Q&A for your repo
- GitHub Pages — Free static site hosting
- Dependabot — Automatic security updates
After years of daily Git usage, these are the advanced techniques, shortcuts, and recovery commands that separate power users from everyone else.
Advanced Git Commands
Interactive Rebase (Rewrite History)
git rebase -i HEAD~5 # Edit last 5 commits
In the editor, you can:
squash— Combine commits into onereword— Change commit messagedrop— Delete a commit entirelyedit— Stop and amend a commit
Pro Tip
Clean up messy commit history before opening a PR. Squash "WIP" and "fix typo" commits into meaningful ones.
Cherry Pick
git cherry-pick abc123 # Apply a specific commit to current branch
Perfect for pulling a bug fix from one branch to another without merging everything.
Reflog (Git's Safety Net)
git reflog # See all HEAD movements
git reset --hard HEAD@{3} # Go back to a previous state
Even after a bad reset or deleted branch, reflog can save you. Git remembers everything for ~90 days.
Bisect (Find Buggy Commits)
git bisect start git bisect bad # Current commit is broken git bisect good v1.0.0 # This version worked # Git will binary search to find the breaking commit
GitHub CLI (gh)
The official CLI is incredibly powerful:
gh pr create --fill # Create PR from current branch gh pr checkout 123 # Check out PR #123 locally gh pr merge --squash # Squash merge current PR gh issue list --assignee @me # Your assigned issues gh repo clone owner/repo # Clone with one command gh run watch # Watch CI/CD in terminal
Aliases (Speed Up Everything)
Add to ~/.gitconfig:
[alias]
co = checkout
br = branch
ci = commit
st = status
lg = log --oneline --graph --all
undo = reset HEAD~1 --mixed
amend = commit --amend --no-edit
wip = !git add -A && git commit -m 'WIP'
pushf = push --force-with-lease # Safer force push
Advanced Workflows
Signed Commits
git config --global commit.gpgsign true # Verify commits are from you
Worktrees (Multiple Branches Simultaneously)
git worktree add ../hotfix hotfix-branch # Work on two branches at once
Partial Staging
git add -p # Stage specific chunks, not whole files
Power Move
Use git add -p to split a day's work into logical, atomic commits. Your code reviewers will thank you.
Recovery Commands
git reset --soft HEAD~1— Undo commit, keep changes stagedgit reset --mixed HEAD~1— Undo commit, keep changes unstagedgit reset --hard HEAD~1— Undo commit, delete changes (careful!)git checkout -- .— Discard all unstaged changesgit clean -fd— Remove untracked files and directories
GitHub Keyboard Shortcuts
- Press
.on any repo to open it in VS Code (web) - Press
tto fuzzy-find files - Press
bto see blame view - Add
?w=1to diff URLs to ignore whitespace - Add
.patchto any commit URL for downloadable patch - Use
github.devinstead ofgithub.comfor full VS Code editor