简体   繁体   English

克隆本地git repo,就像我从其远程克隆一样

[英]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.

相关问题 当我从github远程仓库克隆时,远程仓库的哪个分支被克隆到本地仓库? - When I clone from github remote repo, which branch of remote repo is cloned to local repo? 可以将本地Git克隆视为克隆的repo的完整备份吗? - Can a local Git clone be considered a complete backup of the repo it was cloned from? 是否可以从克隆的 git repo 中提取或克隆? - Is it possible to pull or clone from the cloned git repo? 如何将本地git文件夹(repo)克隆到远程服务器 - How do I clone a local git folder(repo) to a remote server 无法将远程 git repo 从 cPanel 克隆到本地 PC - Can't clone remote git repo from cPanel to local PC 使用git clone --depth 1克隆repo后,如何获取远程分支 - How do fetch remote branch after I cloned repo with git clone --depth 1 与Git混淆。 我应该将我的更改推送到我克隆的仓库吗? - Confusion with Git. Should I push my changes to the repo from where I had cloned? 如果还没有与我的本地存储库链接的远程存储库,我如何 go 到克隆的存储库并签入 git bash? - How do I go to the cloned repo and check in git bash if there isn't already a remote repo linked with my local repo? git clone从local到remote - git clone from local to remote 如何从--share --bare克隆的远程git提取/获取本地仓库 - how to git pull/fetch local repo from remote where cloned with --share --bare
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM