Git Remotes Cheat Sheet

Managing Git remotes — multiple upstreams, origin management, fetch vs pull, upstream tracking, remote branches, and fork synchronization.

Last Updated: May 1, 2025

Remote Management

git remote -v
List all remotes with fetch/push URLs
git remote add name url
Add a new remote repository
git remote rename old new
Rename a remote
git remote remove name
Remove a remote
git remote set-url name newurl
Change the URL of an existing remote
git remote show origin
Inspect remote: branches, tracking, config
git remote prune origin
Clean stale remote-tracking branches
git remote update
Fetch from all remotes

Fetch vs Pull

git fetch origin
Download all changes from remote (no merge)
git fetch origin branch
Fetch a specific branch
git pull origin main
Fetch AND merge remote changes
git pull --rebase origin main
Fetch and rebase (cleaner history)
git fetch --all
Fetch from all configured remotes
git pull --ff-only
Only fast-forward — fail if merge needed
git fetch --prune
Fetch and remove stale remote-tracking refs
git fetch --tags
Fetch all tags from remote

Fork Workflow

gh repo fork
Fork a repository via GitHub CLI
git remote add upstream original-url
Add the original repo as upstream
git fetch upstream
Download latest changes from upstream
git merge upstream/main
Merge upstream changes into your local main
git rebase upstream/main
Rebase your work on latest upstream
git push origin main
Push synced main to your fork
gh pr create --base upstream:main
Create PR from fork to upstream

Upstream Tracking

git push -u origin branch
Push and set upstream tracking (--set-upstream)
git branch -u origin/branch
Set upstream for current branch
git branch --unset-upstream
Remove upstream tracking
git branch -vv
Show all branches with tracking info
git push --force-with-lease
Force push safely (respects remote changes)
git push origin --delete branch
Delete a remote branch
git config --global push.default current
Push current branch to same-name remote
Pro Tip: Name your remotes descriptively: 'origin' for your fork, 'upstream' for the original repo. This convention is universal and tools expect it.