在 Git 中替换 remote.origin.url 的最佳方法是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2420056/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 04:08:33  来源:igfitidea点击:

What's the best way to replace remote.origin.url in Git?

gitversion-control

提问by suzukimilanpaak

I'm new to Git. Let's say Alice and Bob had been developing their project by using two Git repositories for each. And, Alice at certain times want to set up a new repository to manage their common progress. Do you think what is the best way to replace remote.origin.url in the configuration of Git?

我是 Git 的新手。假设 Alice 和 Bob 一直在通过为每个人使用两个 Git 存储库来开发他们的项目。并且,Alice 在某些时候想要建立一个新的存储库来管理他们的共同进度。你认为在Git的配置中替换remote.origin.url的最佳方式是什么?

  • to replace by git config --replace
  • to create new repos by git clone MAIN_REPOS
  • or any?
  • 替换为 git config --replace
  • 通过 git clone MAIN_REPOS 创建新的 repos
  • 或任何?

回答by CB Bailey

If they already have a remote called originbut want the new remote to be called originthen the most logical thing to do is rename or remove the existing remote called originand add a new one:

如果他们已经有一个远程调用,origin但想要调用新的远程,origin那么最合乎逻辑的做法是重命名或删除现有的远程调用origin并添加一个新的远程:

git remote rename origin old_origin

git remote add origin url://new/url.git

If you don't care about the old origin you canjust reset the URL, but you would probably want to do a full git fetchand a git remote prune originafterwards for tidiness.

如果您不关心旧的来源,您可以只重置 URL,但您可能想要做一个完整的git fetchgit remote prune origin之后的整洁。

git config remote.origin.url url://new/url.git

If you have a very recent git (>1.7.0), you have a remote sub command for this:

如果你有一个最新的 git (>1.7.0),你有一个远程子命令:

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