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

  1. Add a remote:
git remote add origin https://github.com/user/repo.git
  1. Verify remotes:
git remote -v
  1. Rename a remote:
git remote rename origin upstream
  1. Remove a remote:
git remote remove upstream

Tips

  • Multiple remotes are useful for forks (e.g., origin and upstream).
  • Use SSH URLs for passwordless authentication.
  • git remote set-url origin <new-url> updates an existing remote.

Common issues

  • Wrong remote URL: verify with -v and update if needed.
  • Permission denied: ensure you have access and correct credentials.