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 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

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

That’s it. You have successfully changed the URL of the remote.

8 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!

    Like

  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!

    Like

  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!

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this:
search previous next tag category expand menu location phone mail time cart zoom edit close