Skip to main content

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.

Updated: 2026-07-15·18 commands

Quick Reference

ScenarioCommand
View remote URLsgit remote -v
Add a remotegit remote add origin
Change remote URLgit remote set-url origin
Remove a remotegit remote remove
Push to remotegit push origin main
Pull from remotegit pull origin main
Fetch without merginggit fetch origin
Set upstream branchgit 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)

CommandLevel
git remote -v
Show all remote repository URLs
Basic
git remote add
Add a new remote repository
Basic
git remote remove
Remove a remote repository
Basic
git remote rename
Rename a remote repository
Basic
git remote set-url
Change the URL of a remote repository
Basic
git remote show
Show detailed information about a remote repository
Intermediate
git remote prune
Delete stale remote-tracking branches
Intermediate
git remote update
Fetch updates from all remote repositories
Basic
git remote get-url
Get the URL of a remote repository
Basic
git fetch
Download objects and refs from a remote repository
Basic
git fetch --prune
Fetch updates and prune stale remote-tracking branches
Intermediate
git pull
Fetch from and integrate with a remote repository
Basic
git push
Push local commits to a remote repository
Basic
git push --set-upstream
Push and set the upstream tracking branch
Intermediate
git push --force-with-lease
Force push with safety check on remote state
Expert
git push --tags
Push all local tags to the remote repository
Basic
git clone
Clone a remote repository to the local machine
Basic
git ls-remote
List references in a remote repository
Intermediate

FAQ

This cheatsheet is compiled from official tool documentation. Last updated: 2026-07-15.