Git Remote Cheatsheet — push / pull / fetch & Upstreams
Remote repositories let you collaborate with others, backup your code, and deploy from anywhere. This guide covers the key remote workflows — from your first push to managing multiple remotes.
Quick Reference
| Scenario | Command |
| View remote URLs | git remote -v |
| Add a remote | git remote add origin |
| Change remote URL | git remote set-url origin |
| Remove a remote | git remote remove |
| Push to remote | git push origin main |
| Pull from remote | git pull origin main |
| Fetch without merging | git fetch origin |
| Set upstream branch | git push -u origin main |
Core Commands
### Managing Remotes
``bash
# List all remotes
git remote -v
# Add a new remote git remote add origin https://github.com/user/repo.git
# Change remote URL git remote set-url origin git@github.com:user/repo.git
# Remove a remote
git remote remove upstream
`
### Pushing & Pulling
`bash
# Push to remote (first time - sets upstream)
git push -u origin main
# Push to remote (subsequent) git push
# Force push (use with extreme caution!) git push --force-with-lease
# Pull and merge git pull origin main
# Pull with rebase instead of merge
git pull --rebase origin main
`
### Fetching
`bash
# Fetch all branches from origin
git fetch origin
# Fetch a specific branch git fetch origin feature-branch
# Review fetched changes before merging
git fetch origin
git log HEAD..origin/main # See what's new
git merge origin/main # Merge when ready
`
### Working with Multiple Remotes
`bash
# Add a second remote (e.g., fork workflow)
git remote add upstream https://github.com/original/repo.git
# Fetch from upstream git fetch upstream
# Merge upstream changes git checkout main git merge upstream/main ``
Remote(18)
| Command | Level | ||
|---|---|---|---|
git remote -vShow all remote repository URLs | Basic | git remote -v | |
git remote addAdd a new remote repository | Basic | git remote add origin https://github.com/user/repo.git | |
git remote removeRemove a remote repository | Basic | git remote remove origin | |
git remote renameRename a remote repository | Basic | git remote rename origin upstream | |
git remote set-urlChange the URL of a remote repository | Basic | git remote set-url origin https://github.com/newuser/repo.git | |
git remote showShow detailed information about a remote repository | Intermediate | git remote show origin | |
git remote pruneDelete stale remote-tracking branches | Intermediate | git remote prune origin | |
git remote updateFetch updates from all remote repositories | Basic | git remote update | |
git remote get-urlGet the URL of a remote repository | Basic | git remote get-url origin | |
git fetchDownload objects and refs from a remote repository | Basic | git fetch origin | |
git fetch --pruneFetch updates and prune stale remote-tracking branches | Intermediate | git fetch --prune origin | |
git pullFetch from and integrate with a remote repository | Basic | git pull origin main | |
git pushPush local commits to a remote repository | Basic | git push origin main | |
git push --set-upstreamPush and set the upstream tracking branch | Intermediate | git push --set-upstream origin feature-login | |
git push --force-with-leaseForce push with safety check on remote state | Expert | git push --force-with-lease origin main | |
git push --tagsPush all local tags to the remote repository | Basic | git push --tags origin | |
git cloneClone a remote repository to the local machine | Basic | git clone https://github.com/user/repo.git | |
git ls-remoteList references in a remote repository | Intermediate | git ls-remote origin |