Changing a Git Remote’s URL

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:

  1. 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 (fetch)
    $ origin (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 this:

5. If you’re changing to SSH, the URL will look like this:

For example, to change the origin to you would type:

 $ git remote set-url origin
That’s it. You have successfully changed the URL of the remote.
The feeling you get when you are able to change the URL of the remote.
That feeling when you are able to change the Git’s remote URL

10 thoughts on “Changing a Git Remote’s URL”

  1. 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!

  2. 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!

  3. 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!

Leave a Comment

Your email address will not be published.