git 离开Github,如何改变一个Git repo的起源?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3011402/
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
Leaving Github, how to change the origin of a Git repo?
提问by Ben Orozco
I'm hosting a project in Github, but now I purchased a plan with Dreamhost that includes shell access and Git.
我在 Github 托管一个项目,但现在我购买了 Dreamhost 的计划,其中包括 shell 访问和 Git。
Github [Origin]
/ \
pull/ \pull
/push push\
/ \
Laptop Dreamhost
(cloned) (cloned)
I would like to delete my repo from Github, and starting push directly to DH.
我想从 Github 删除我的 repo,并直接开始推送到 DH。
How do I change origin in my Laptop, and should I delete the origin in Dreamhost?
如何更改笔记本电脑中的原点,我应该删除 Dreamhost 中的原点吗?
回答by clee
git remote rename origin github
git remote add origin <DreamHost-git-URL>
# test and make sure the DreamHost origin works properly for fetch and push
git remote rm github
I prefer using the 'git remote' command instead of screwing about with the .git/config file by hand.
我更喜欢使用“git remote”命令,而不是手动使用 .git/config 文件。
回答by Octavi Fornés
The easiest way is:
最简单的方法是:
$ git config remote.origin.url <Dreamhost-git-URL>
You show the remotes after this:
在此之后显示遥控器:
$ git remote -v
origin Dreamhost-git-URL (fetch)
origin Dreamhost-git-URL (push)
回答by Adam Dymitruk
The easiest way is to edit your .git/config file on your laptop. Simply search for your github url and replace it with the one from DreamHost. Make sure that your ssh public key is set on Dreamhost. Now you can push origin master and you will have populated your dreamhost repository.
最简单的方法是在笔记本电脑上编辑 .git/config 文件。只需搜索您的 github 网址并将其替换为 DreamHost 的网址即可。确保您的 ssh 公钥已在 Dreamhost 上设置。现在您可以推送 origin master,并且您将填充您的 Dreamhost 存储库。
You can delete origin on dreamhost but there is no need.
您可以在 Dreamhost 上删除原点,但没有必要。
Also, ensure that the repository that is there is bare. By default, you cannot push to non-bare repositories.
另外,请确保那里的存储库是裸的。默认情况下,您无法推送到非裸存储库。
回答by slashingweapon
The best way is to git remote set-url origin <new-url>
最好的方法是 git remote set-url origin <new-url>
回答by Yann Ramin
The easiest way is to edit your .git/config
file, which lists where the origin lives. You can test it by running a git fetch
最简单的方法是编辑您的.git/config
文件,其中列出了原点所在的位置。您可以通过运行一个来测试它git fetch
You can delete the remote references on the Dreamhost side if you like, in the same file.
如果愿意,您可以在同一文件中删除 Dreamhost 端的远程引用。
回答by gjambet
why not simply :
为什么不简单:
git remote remove origin
git remote add origin <Dreamhost-git-URL>
git push -u origin --all