How to Change the URL of a Git Remote

We may receive a commission for purchases made through the links on our site. This helps us keep everything up and running.
How to Change the URL of a Git Remote

Git is among the most popular versions control systems in the world in the present. Every kind in software creation, from small projects to enterprise-level production products, everything is using Git in the present.

While Git is an uncentralized system for controlling the version of code, i.e., each user has their personal copy of code, it is typically an underlying remote repository in which the code is kept. Users can upload their code into this repository and pull it from it. Developers can then share their modifications with one another through the central repository.

The Git remote acts as the remote server or repository in which the code is kept centrally. Git keeps the URL of the repository, which is known as the’remote URL’, which is the name of the remote. The remote of this central repository can be quite often referred to as the origin. The URL that is used for the origin is used when modifications are required to be pulled or pushed.

To view your Git remote’s URL, start:

git remote get-url 

To change the Git Remote URL run:

remote set-url for git remote_name> new_url>

As you will see below, we have changed the URL of remote source to Github to Github repository, to the Gitlab repository.

Be aware it is important to note that the distant source must be in place in order that the the set-url command is able to modify its URL.

To create a new remote, make use of the git remote-add command. For more details on this command and other git remote commands, type the git assist remote.

Related