Open In App

How to Change the URI For a Remote Git Repository?

Last Updated : 31 May, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Git is a distributed version control system that helps manage source code history. Sometimes, you may need to change the URI (URL) of a remote repository, for instance, when migrating to a new host or changing from HTTP to SSH. Here’s how you can accomplish this task.

Changing the URI for a remote Git repository is essential when the location or access method of your remote repository changes. This can happen for various reasons such as migrating repositories, changing the repository hosting service, or switching from HTTP to SSH for better security. Git provides simple commands to update the remote repository URL.

Using the `git remote set-url` command

Using the `git remote set-url` Command

The `git remote set-url` command is the most straightforward way to change the remote repository URL. This command updates the remote repository’s URL to the new address you provide.

Step-by-Step Guide:

1. Open your terminal or command prompt: Navigate to your local Git repository.

cd  /path/to/your/repo

2. Verify the current remote URL: Use the `git remote -v` command to see the current remote URLs.

git remote -v

Output:

origin  https://old-url.com/user/repo.git (fetch)
origin https://old-url.com/user/repo.git (push)

3. Change the remote URL: Use the `git remote set-url` command to update the URL.

git remote set-url origin https://new-url.com/user/repo.git

4. Verify the change: Run `git remote -v` again to confirm the new URL.

git remote -v

Output:

origin  https://new-url.com/user/repo.git (fetch)
origin https://new-url.com/user/repo.git (push)

Demonstration with an Example:


Next Article
Article Tags :

Similar Reads