git remote Command Guide
Manage set of tracked repositories
Dai Aoki
CEO at init, Inc. / CTO at US & JP startups / Creator of WebTerm
Quick Reference
List
git remoteList remote namesgit remote -vList with URLsgit remote show <name>Show detailsManage
git remote add <name> <url>Add remotegit remote remove <name>Remove remotegit remote rename <old> <new>Rename remoteUpdate
git remote set-url <name> <url>Change URLgit remote prune <name>Remove stale refsDownloadable Image Preview
Basic Usage
The git remote command manages connections to remote repositories. These are shortcuts to URLs you push to and pull from.
# List configured remotes
git remote
# List with URLs (verbose)
git remote -v
# origin git@github.com:user/repo.git (fetch)
# origin git@github.com:user/repo.git (push)
# Show detailed info about a remote
git remote show originAdding Remotes
# Add a remote
git remote add origin git@github.com:user/repo.git
# Add with HTTPS
git remote add origin https://github.com/user/repo.git
# Add upstream (for forks)
git remote add upstream https://github.com/original/repo.git
# Verify
git remote -vManaging Remotes
# Remove a remote
git remote remove origin
git remote rm origin # Short form
# Rename a remote
git remote rename origin github
# Change URL
git remote set-url origin git@github.com:user/new-repo.git
# Change push URL only
git remote set-url --push origin git@github.com:user/repo.git
# Clean up deleted remote branches
git remote prune origin| Command | Description |
|---|---|
| add <name> <url> | Add a new remote |
| remove <name> | Remove a remote |
| rename <old> <new> | Rename a remote |
| set-url <name> <url> | Change URL |
| prune <name> | Remove stale branches |
Working with Multiple Remotes
# Fork workflow: origin (your fork) + upstream (original)
git remote add origin git@github.com:you/repo.git
git remote add upstream git@github.com:original/repo.git
# Fetch from upstream
git fetch upstream
# Merge upstream changes
git merge upstream/main
# Push to your fork
git push origin main
# List all remote branches
git branch -rPractical Examples
# Switch from HTTPS to SSH
git remote set-url origin git@github.com:user/repo.git
# Add remote for deployment
git remote add production git@server.com:app.git
git push production main
# Check remote status
git remote show origin
# Prune while fetching
git fetch --prune origin
# See what branches track what
git branch -vvFrequently Asked Questions
What is "origin" in Git?
"origin" is the default name for the remote repository when you clone. It's just a convention - you can name remotes anything.
How do I change a remote URL?
Use "git remote set-url <name> <new-url>". Common when switching from HTTPS to SSH or moving repositories.
Can I have multiple remotes?
Yes! You can add multiple remotes (e.g., origin, upstream) to push/pull from different repositories, useful for forks.
What does git remote prune do?
It removes references to remote branches that no longer exist on the remote. Run "git fetch --prune" to fetch and prune in one step.
Summary
git remote manages your connections to remote repositories. Use multiple remotes for forks and different deployment targets.
Quick Reference
git remote -v- List remotes with URLsgit remote add <name> <url>- Add remotegit remote set-url- Change URLgit remote prune- Clean stale refs
Official Documentation
For authoritative information, refer to the official documentation: