Each Git repository can have zero or more Git remotes linked to it. When you clone a repository, the name of the remote is set automatically to origin and points to the repository that you cloned from. If you created the repository locally, you can add a new remote.
Just follow the steps below to change the URL of a remote:
- Go to the directory where your repository is located:
$ cd /path/repository
git remote to list the existing remotes with names and URLs:
$ git remote -v
You would get:
$ origin https://github.com/user/repo_name.git (fetch) $ origin https://github.com/user/repo_name.git (push)
3. Use the
git remote set-url command followed by the remote name, and the remote’s URL:
$ git remote set-url <remote-name> <remote-url>
The remote’s URL can start with HTTPS or SSH, depending on the protocol you’re using. If no protocol is specified, it defaults to SSH. The URL can be found on the repository page of your Git hosting service.
4. If you’re changing to HTTPS, the URL will look something like:
5. If you’re changing to SSH, the URL will look like:
For example, to change the
email@example.com:user/repo_name.git you would type:
$ git remote set-url origin firstname.lastname@example.org:user/repo_name.git
That’s it. You have successfully changed the URL of the remote.