git remote
Description:
Manage set of tracked repositories. Remote repositories are versions of your project hosted on the internet or network.
Syntax:
bash
git remote
git remote -v
git remote add <name> <url>
git remote remove <name>
git remote rename <old> <new>
git remote set-url <name> <new-url>Examples:
bash
# List all remotes
git remote
# Output: origin
# List remotes with URLs
git remote -v
# Output:
# origin https://github.com/user/repo.git (fetch)
# origin https://github.com/user/repo.git (push)
# Add a new remote
git remote add upstream https://github.com/original/repo.git
# Remove a remote
git remote remove upstream
# Rename a remote
git remote rename origin github
# Change remote URL
git remote set-url origin https://github.com/user/new-repo.gitDetailed Explanation:
- origin - Default name for the primary remote repository
- upstream - Commonly used for the original repository when working with forks
- Multiple remotes - You can have multiple remotes for different purposes (origin, backup, production)
- SSH vs HTTPS - Remotes can use SSH (
git@github.com:user/repo.git) or HTTPS URLs
Common Errors:
fatal: remote origin already exists→ Solution: Remove the existing remote first:git remote remove originfatal: No such remote 'name'→ Solution: Check remote names withgit remote -vPermission denied (publickey)→ Solution: Set up SSH keys or use HTTPS with credentials
Pro Tips:
- Use
git remote show originto see detailed information about a remote - Convention:
originfor your fork,upstreamfor the original repository - Use
git remote prune originto clean up deleted remote branches - Changing remote URLs doesn't affect your local commits
Related Commands: