DEV Community

Cover image for How to change the URI (URL) for a remote Git repository?
Suresh Ramani
Suresh Ramani

Posted on • Originally published at techvblogs.com

How to change the URI (URL) for a remote Git repository?

What is Git?

Git is the world's most popular distributed version control system used by many open-source and commercial projects. It allows you to collaborate on projects with your fellow developers, keep track of your code changes, revert to previous stages, create branches, and more. Linus Torvalds (the creator of Linux) developed Git.

Git is software for tracking changes in any set of files, usually used for coordinating work among programmers collaboratively developing source code during software development. Its goals include speed, data integrity, and support for distributed, non-linear workflows.

A version control system is a system that keeps a record of the changes in a file (or multiple files) over a period. This is so that a user may return to a previous version of the system's software whenever necessary.

Features of Git

  • Tracks history.
  • Free and open source.
  • Supports non-linear development.
  • Creates backups.
  • Scalable.
  • Supports collaboration.
  • Branching is easier.
  • Distributed development.

What is Git Remote URI(URL)?

Git remote is a pointer that refers to another copy of the repository that is usually hosted on a remote server.

In some situations, like when the remote repository is migrated to another host, you need to change the remote’s URL.

In this tutorial, you are going to learn how you can change the URL of a Git remote easily.

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.

Follow the steps below to change the URL of a remote:
1 - Change to the directory where the repository is located:

cd /path/to/repository
Enter fullscreen mode Exit fullscreen mode

2 - Run git remote to list the existing remotes and see their names and URLs:

git remote -v
Enter fullscreen mode Exit fullscreen mode

3 - Use the git remote set-url a command followed by the remote name, and the remote’s URL:

git remote set-url <remote-name> <remote-url>
Enter fullscreen mode Exit fullscreen mode

If you’re changing to HTTPS, the URL will look something like this:

https://gitserver.com/user/repo_name.git
Enter fullscreen mode Exit fullscreen mode

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

git@gitserver.com:user/repo_name.git
Enter fullscreen mode Exit fullscreen mode

4 - Verify that the remote’s URL was successfully changed by listing the remote connections:

git remote -v
Enter fullscreen mode Exit fullscreen mode

That’s it. You have successfully changed the URL of the remote.
Thank you for reading this blog.

Top comments (0)