How to change the URL of the origin remote repository in Git

To change the URL of the origin remote repository in Git, you can follow these steps:

1. Verify the current remote URL:

First, check the current remote repository URL by running:

1
git remote -v

This will show the current URLs for your remote repository, usually something like:

1
2
origin  https://github.com/username/repository.git (fetch)
origin https://github.com/username/repository.git (push)

2. Change the remote URL:

To update the remote URL, you can use the git remote set-url command. Here’s how to change it:

1
git remote set-url origin <new-remote-url>

For example, if your new remote URL is https://github.com/newuser/newrepository.git, you would run:

1
git remote set-url origin https://github.com/newuser/newrepository.git

3. Verify the change:

After changing the URL, you can verify that it was updated correctly by running:

1
git remote -v

This should now display the new URL for the origin remote.

4. Optional - Push to the new remote:

If you’ve changed the remote to a different repository, you can now push your changes:

1
git push origin <branch-name>

That’s it! You’ve successfully changed the URL of the origin remote repository.


How to change the URL of the origin remote repository in Git
https://www.hardyhu.cn/2024/10/24/How-to-change-the-URL-of-the-origin-remote-repository-in-Git/
Author
John Doe
Posted on
October 24, 2024
Licensed under