Adding a remote repository
To add a new remote, use the git remote add command on the terminal, in the directory your repository is stored at.
The git remote add command takes two arguments:
- A remote name, for example,
origin - A remote URL, for example,
https://[hostname]/user/repo.git
For example:
$ git remote add origin https://hostname/user/repo.git
# Set a new remote
$ git remote -v
# Verify new remote
> origin https://hostname/user/repo.git (fetch)
> origin https://hostname/user/repo.git (push)
For more information on which URL to use, see "About remote repositories."
Troubleshooting: Remote origin already exists
This error means you've tried to add a remote with a name that already exists in your local repository.
$ git remote add origin https://hostname/octocat/Spoon-Knife.git
> fatal: remote origin already exists.
To fix this, you can:
- Use a different name for the new remote.
- Rename the existing remote repository before you add the new remote. For more information, see "Renaming a remote repository" below.
- Delete the existing remote repository before you add the new remote. For more information, see "Removing a remote repository" below.
Changing a remote repository's URL
The git remote set-url command changes an existing remote repository URL.
Tip: For information on the difference between HTTPS and SSH URLs, see "About remote repositories."
The git remote set-url command takes two arguments:
- An existing remote name. For example,
originorupstreamare two common choices. - A new URL for the remote. For example:
- If you're updating to use HTTPS, your URL might look like:
https://[hostname]/USERNAME/REPOSITORY.git - If you're updating to use SSH, your URL might look like:
git@hostname:USERNAME/REPOSITORY.git
- If you're updating to use HTTPS, your URL might look like:
Switching remote URLs from SSH to HTTPS
- Open TerminalTerminalGit Bash.
- Change the current working directory to your local project.
- List your existing remotes in order to get the name of the remote you want to change.
$ git remote -v > origin git@