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.
The remote can point to a repository hosted on a Git hosting service such as GitHub, BitBucket or GitLab.
Just follow the steps below to change the URL of a remote:
- Go to the directory where your repository is located:
$ cd /path/repository
2. Run 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:
https://gitserver.com/user/repo_name.git
5. If you’re changing to SSH, the URL will look like:
git@gitserver.com:user/repo_name.git
For example, to change the origin
to git@gitserver.com:user/repo_name.git
you would type:
$ git remote set-url origin git@gitserver.com:user/repo_name.git

That’s it. You have successfully changed the URL of the remote.
I have long looked for Changing a Git Remote’s URL – THE DEVELOPER STORY article, it is the BEST content, full of ideas and very useful!!
Thank you for this information, good luck!
LikeLike
Thank you Jere! 🙂
LikeLike
cool post. I just stumbled upon your post and wished to say that I’ve really enjoyed reading your blog post. After all I’ll be subscribing to your rss feed and I hope you write again soon!
LikeLike
Thanks Carlos!
LikeLike
Wow that was strange. I just wrote an incredibly long comment but after I clicked submit my comment didn’t show up. Grrrr… well I’m not writing all that over again. Anyways, just wanted to say wonderful blog!
LikeLike
Thanks Francis!
LikeLike
That was good👍👍
LikeLiked by 1 person
Thanks, Shrusti!
LikeLike