+5 votes
1 view
in Devops and Agile by (26k 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

+6 votes
by (43.8k 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:

Welcome to Intellipaat Community. Get your technical queries answered by top developers !