Git: How to change the remote URL of a repository?
Sep 16, 2021 - by kurinchilamp / / Post Comment
Let's first display the remote URL that is set for the repository.
$ git remote -v
origin https://github.com/USER/my-repo-main.git (fetch)
origin https://github.com/USER/my-repo-main.git (push)
Option 1:
If we want to change the URL that is set to that of a different user USER2, then we can do that by issuing the command
$ git remote set-url origin https://github.com/USER2/my-repo-main.git
Option 2:
Another workaround for this task is to edit .git/config file and replace the url present in the file to that of the new git URL.
$ cat .git/config
[core]
.....
[remote "origin"]
url = https://github.com/USER/my-repo-main.git
$ sudo vi .git/config
[core]
.....
[remote "origin"]
url = https://github.com/USER2/my-repo-main.git
Continue Reading