Skip to main content

Remote Operations Cheatsheet

Remotes

CommandAction
git remote -vList remotes with URLs
git remote add <name> <url>Add a remote
git remote remove <name>Remove a remote
git remote rename <old> <new>Rename a remote
git remote set-url <name> <url>Change remote URL

Fetch

CommandAction
git fetchDownload from default remote
git fetch originDownload from origin
git fetch --allDownload from all remotes
git fetch --pruneFetch + remove stale branches

Pull

CommandAction
git pullFetch + merge current tracking
git pull origin mainPull specific branch
git pull --rebaseFetch + rebase (no merge commit)
git pull --rebase origin mainRebase pull from specific

Push

CommandAction
git pushPush to tracking remote
git push origin mainPush specific branch
git push -u origin <branch>Push + set upstream tracking
git push --allPush all branches
git push --tagsPush all tags
git push --force-with-leaseSafe force push
git push --forceForce push (dangerous)
git push origin --delete <branch>Delete remote branch

Tags

CommandAction
git tagList all tags
git tag v1.0.0Create lightweight tag
git tag -a v1.0.0 -m "msg"Create annotated tag
git tag -d v1.0.0Delete local tag
git push origin v1.0.0Push specific tag
git push --tagsPush all tags
git push origin --delete v1.0.0Delete remote tag

Fork Workflow

CommandAction
git clone <fork-url>Clone your fork
git remote add upstream <url>Add original repo
git fetch upstreamGet upstream changes
git rebase upstream/mainUpdate your branch
git push origin mainPush to your fork

Inspection

CommandAction
git branch -rList remote branches
git log main..origin/mainCommits on remote not local
git log origin/main..mainCommits local not on remote