How to add a remote repository in Git
· Category: Git
Short answer
Use git remote add <name> <url> to link your local repository to a remote server.
Steps
- Add a remote:
git remote add origin https://github.com/user/repo.git
- Verify remotes:
git remote -v
- Rename a remote:
git remote rename origin upstream
- Remove a remote:
git remote remove upstream
Tips
- Multiple remotes are useful for forks (e.g.,
originandupstream). - Use SSH URLs for passwordless authentication.
git remote set-url origin <new-url>updates an existing remote.
Common issues
- Wrong remote URL: verify with
-vand update if needed. - Permission denied: ensure you have access and correct credentials.