Cheatsheet: Remotes and forks
Voice anchor
Section titled “Voice anchor”Git stores snapshots. Every other command is just navigating those snapshots.
Push and pull are navigating snapshots between machines.
Command reference
Section titled “Command reference”# Inspectgit remote -v # list remotes with URLsgit branch -a # list local + remote-tracking branchesgit branch -r # list only remote-tracking branchesgit status # ahead/behind information
# Manage remotesgit remote add upstream <url> # add a remotegit remote remove upstream # remove a remotegit remote rename origin myorigin # rename a remote
# Get changes from remotegit fetch # download without merginggit fetch upstream # fetch from a specific remotegit pull # fetch + merge (default)git pull --rebase # fetch + rebase (preferred)
# Send changes to remotegit push # push current branch (if tracking set)git push -u origin <branch> # first push, sets trackinggit push --force-with-lease # safe force-push (personal branches only)
# Configure global defaults (run once)git config --global pull.rebase true # make pull use rebasegit config --global merge.conflictstyle diff3 # better conflict markers (L7)
# Clonegit clone <url> # full copy of a remote repogit clone <url> <folder-name> # clone into a specific folderThe fork-based model setup
Section titled “The fork-based model setup”# 1. Fork on GitHub (UI click), then:git clone https://github.com/<your-username>/<repo>.gitcd <repo>git remote add upstream https://github.com/<original-owner>/<repo>.gitgit remote -v # verify both remotes
# 2. Stay synced with upstreamgit switch maingit fetch upstreamgit rebase upstream/maingit push origin main
# 3. Contributegit switch -c feature/my-change# ... do work, commitgit push -u origin feature/my-change# ... open PR on GitHub from your fork to upstreamPull-rebase: the one-time global config
Section titled “Pull-rebase: the one-time global config”git config --global pull.rebase trueAfter this, every git pull automatically uses rebase. No more merge-commit clutter.
Caveat: if you have uncommitted changes, git pull --rebase refuses. Either commit first, or git stash + pull + git stash pop.
Force-push decision tree
Section titled “Force-push decision tree”Is the branch shared with others (main, develop, release/*)? YES -> NEVER force-push NO -> continue
Have I rebased / amended commits that are already on the remote? NO -> regular git push works YES -> continue
Has anyone else pushed to this branch since my last fetch? YES -> force-with-lease will refuse; fetch and decide NO -> git push --force-with-lease
NEVER use plain --force unless you 100% understand the consequences.ALWAYS use --force-with-lease as the default safe variant.Remote-tracking branches quick reference
Section titled “Remote-tracking branches quick reference”| Name | What it is |
|---|---|
main (local) | Your local main branch |
origin/main | Read-only label for “what origin’s main looked like at last fetch” |
upstream/main | Read-only label for “what upstream’s main looked like at last fetch” |
To compare:
git log main..origin/main # commits remote has that you don'tgit log origin/main..main # commits you have that remote doesn'tgit diff main origin/main # actual code differencesWhat’s in L9
Section titled “What’s in L9”L9 introduces the three production team workflows: GitHub Flow, GitFlow, and Trunk-based Development. Each is a pattern built on the primitives from L5-L8 (branches, PRs, conflicts, remotes). You’ll learn the tradeoffs, when each fits, and how to choose for your team. After L9, you understand the structural choices behind every production engineering team’s git practices.
L9 opens Phase 3. Phase 3 also covers releases + tags (L10), cherry-pick + stash (L11), and rebase deeper (L12).