Last Updated: May 1, 2025
Remote Management
git remote -vList all remotes with fetch/push URLs
git remote add name urlAdd a new remote repository
git remote rename old newRename a remote
git remote remove nameRemove a remote
git remote set-url name newurlChange the URL of an existing remote
git remote show originInspect remote: branches, tracking, config
git remote prune originClean stale remote-tracking branches
git remote updateFetch from all remotes
Fetch vs Pull
git fetch originDownload all changes from remote (no merge)
git fetch origin branchFetch a specific branch
git pull origin mainFetch AND merge remote changes
git pull --rebase origin mainFetch and rebase (cleaner history)
git fetch --allFetch from all configured remotes
git pull --ff-onlyOnly fast-forward — fail if merge needed
git fetch --pruneFetch and remove stale remote-tracking refs
git fetch --tagsFetch all tags from remote
Fork Workflow
gh repo forkFork a repository via GitHub CLI
git remote add upstream original-urlAdd the original repo as upstream
git fetch upstreamDownload latest changes from upstream
git merge upstream/mainMerge upstream changes into your local main
git rebase upstream/mainRebase your work on latest upstream
git push origin mainPush synced main to your fork
gh pr create --base upstream:mainCreate PR from fork to upstream
Upstream Tracking
git push -u origin branchPush and set upstream tracking (--set-upstream)
git branch -u origin/branchSet upstream for current branch
git branch --unset-upstreamRemove upstream tracking
git branch -vvShow all branches with tracking info
git push --force-with-leaseForce push safely (respects remote changes)
git push origin --delete branchDelete a remote branch
git config --global push.default currentPush 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.