Reputation: 652
I was using this method to add multiple remote repository URLs. I by mistake added same remote url by using this command twice :
git remote set-url origin --push --add <a remote>
So now git remote -v
shows this:
origin https://github.com/<user>/<repo>.git (fetch)
origin https://github.com/<user>/<repo>.git (push) // remote-1
origin https://github.com/<user>/<repo>.git (push) // duplicate reference to same remote-1
origin https://bitbucket.com/<user>/<repo>.git (push) // remote-2
So now, whenever i push, git pushes 3 times, assuming there are 3 URLs.
How can i remove this duplicate URL, while keeping the original & the new remote reference.
Upvotes: 2
Views: 930
Reputation: 4484
You can use something like
git remote set-url --push --delete origin <url>
and then re-add the URL only once.
The git documentation on set-url
states:
set-url Changes URLs for the remote. Sets first URL for remote that matches regex (first URL if no is given) to . If doesn’t match any URL, an error occurs and nothing is changed.
With --push, push URLs are manipulated instead of fetch URLs.
With --add, instead of changing existing URLs, new URL is added.
With --delete, instead of changing existing URLs, all URLs matching regex are deleted for remote . Trying to delete all non-push URLs is an error.
So we can just combine the --push
and --delete
parameters to achieve what we want.
Upvotes: 5