[英]Clone a local git repo as if I had cloned from its remote
I have a local git repo that I cloned from a remote (github, say). 我有一个从远程克隆的本地git存储库(例如,github)。 The branches in this have associated upstreams that they pull and push from.
其中的分支具有相关联的上游,它们从中进行推拉。
I'd like to make a new local copy of this repo so that I can be simultaneously developing on different branches locally. 我想为此仓库创建一个新的本地副本,以便可以同时在本地的不同分支上进行开发。
I could just git clone …
from the remote repo, but this will take a while over a slow link. 我可以从远程存储库中进行
git clone …
,但这将花费一些时间通过缓慢的链接。
Instead, I'd like to git clone
from the local repo, but have the effect be as if I had done a git clone
of the remote. 取而代之的是,我想从本地仓库中
git clone
,但是效果就好像我做了远程的git clone
。 So, branches in the new copy will pull and push from the remote. 因此,新副本中的分支将从远程拉入和推入。 For any other operation that needs a remote it will use the original remote.
对于需要遥控器的任何其他操作,它将使用原始遥控器。
How can I do this? 我怎样才能做到这一点? … should I just
cp -r repo repo-clone
? …我应该只使用
cp -r repo repo-clone
吗?
If you actually don't want a new clone, but just checkout multiple worktrees for different branches, you might also consider `git worktree' instead. 如果您实际上不想要新的克隆,而只是签出多个分支的不同分支的工作树,则也可以考虑使用“ git worktree” 。
If you really want to clone and save the time and bandwith for download, you do the clone form the remote as usual, but you add --reference <local repository>
to use the Git objects from the local repository instead of downloading them from the remote. 如果您确实要克隆并节省时间和带宽以进行下载,则可以像往常一样从远程进行克隆,但是您可以添加
--reference <local repository>
以使用--reference <local repository>
的Git对象,而不是从本地存储库中下载它们。远程。 This will use the objects from the reference repository and not copy them, so it could happen that some Git cleanup deletes objects that you need in your second clone if you eg delete a branch in the reference repository that is still in the new repository and the commits are not reachable anymore in the reference repository. 这将使用参考存储库中的对象而不复制它们,因此,如果您删除了仍在新存储库中的参考存储库中的分支,则某些Git清理可能会删除第二个克隆中所需的对象。提交在参考资料库中不再可用。 If you want to spend additional diskspace to overcome this, use additionally
--dissociate
to actually copy the objects from the reference repository. 如果您想花费更多的磁盘空间来解决此问题,请另外使用
--dissociate
从参考存储库中实际复制对象。
You can git clone /local/git/repo
from the local repo and use 您可以从本地仓库
git clone /local/git/repo
repo并使用
git remote rename origin old_origin
git remote add origin <PATH>
to add the remote repo. 添加远程仓库。 and maybe delete the initial repo with
并可能会删除初始仓库
git remote remove old_origin
Use git remote -h
for more information 使用
git remote -h
获取更多信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.