Git:将存储库克隆到新存储库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17546246/
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
Git: cloning repository into new repository
提问by Aly
I am using Git (on bitbucket) and have a repository with my code. I now want to use this code and largely modify it for another project all together. I understand that I should abstract the common components to a third library and use that but for the sake of argument, if I want to clone the current repository into a new one, is this possible without manually just copying the code and pushing to a new repo?
我正在使用 Git(在 bitbucket 上)并且有一个包含我的代码的存储库。我现在想使用这段代码,并在很大程度上为另一个项目修改它。我知道我应该将公共组件抽象到第三个库并使用它,但为了争论,如果我想将当前存储库克隆到一个新存储库中,这是否可能无需手动复制代码并推送到新的回购?
Thanks,
谢谢,
Aly
阿里
回答by RyPeck
First clone the repository you want to work with. This step could be skipped if you want it all to happen in the folder you are already in.
首先克隆您要使用的存储库。如果您希望这一切都发生在您所在的文件夹中,则可以跳过此步骤。
git clone file:///path/to/repo/
Cloning will bring over the remotes specified in that directory. So you'll need to remove the remotesyou don't want.
克隆将带来该目录中指定的遥控器。所以你需要删除你不想要的遥控器。
git remote rm <remote>
And add the ones you do, after you have created your remote repository.
并在创建远程存储库后添加您所做的。
git remote add origin <url>
You will also want to --set-upstream-to
, or -u
to tell git this is the remote repository this branch will update to, presuming you are on the master branch.
您还需要--set-upstream-to
或-u
告诉 git 这是此分支将更新到的远程存储库,假设您在 master 分支上。
git push -u origin master
Then you'll need to decide which branches to keep and add to the remote. If you want to push all of them, just do git push --mirror
. This will push all your tags and your remotes. But since we edited your remotes in an earlier step, it shouldn't be a problem.
然后您需要决定保留哪些分支并将其添加到远程。如果您想推送所有这些,只需执行git push --mirror
. 这将推送您的所有标签和遥控器。但是由于我们在前面的步骤中编辑了您的遥控器,所以这应该不是问题。
If you only want to keep a few, you can git push -u origin <branch>
each one you want.
如果你只想保留几个,你可以git push -u origin <branch>
每个你想要的。
回答by Mobiletainment
You can simply use set-url
to push your existing repository into a new repository:
您可以简单地使用set-url
将现有存储库推送到新存储库中:
cd file:///path/to/repo/
git remote set-url origin <url-of-new-repo>
git push -u origin master
cd file:///path/to/repo/
git remote set-url origin <url-of-new-repo>
git push -u origin master
回答by mnagel
you can either clone the existing repo and remove the remotes, or you can copy the folder on the filesystem and change/remove the remotes in one copy.
您可以克隆现有的 repo 并删除遥控器,也可以复制文件系统上的文件夹并在一个副本中更改/删除遥控器。
but as your question is not too clear, here another thing that is possible:
但由于您的问题不太清楚,这里还有另一件事是可能的:
add another remote to an existing remote (besides origin) and push to that remote.
将另一个遥控器添加到现有遥控器(除了 origin)并推送到该遥控器。