Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
309 views
in Technique[技术] by (71.8m points)

git remove duplicate remote URLs

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...