Back

Explore Courses Blog Tutorials Interview Questions
+4 votes
2 views
in DevOps and Agile by (29.3k points)
edited by

I just did git init to initialize my folder as git repo and then added a remote repository using git remote add origin url. Now I want to remove this git remote add origin and add a new repository git remote add origin new-url. How can I do it?

1 Answer

+5 votes
by (50.2k points)
edited by

Instead of removing and adding the url I would suggest something like this

git remote set-url origin git://new.url.here

This will resolve your query.

Changes URLs for the remote will Set it's first URL for remote <name> that matches regex <oldurl> to <newurl>. If <oldurl> doesn’t match any URL, an error occurs and nothing is changed.

Reference: https://git-scm.com/docs/git-remote#Documentation/git-remote.txt-emset-urlem

For more information about the installation of git and common git commands please go through the following link:

Browse Categories

...