简体   繁体   English

复制克隆的仓库并签出新分支

[英]copying a cloned repo and checking out new branch

If I clone a repo's master branch, can I copy this repo and paste it into another folder and checkout another branch? 如果克隆仓库的主分支,是否可以复制此仓库并将其粘贴到另一个文件夹并签出另一个分支?

The reason I'm asking is because the repo I'm cloning is huge, and each track requires a new database to run properly. 我要问的原因是因为我要克隆的存储库很大,并且每个轨道都需要一个新的数据库才能正常运行。 Because of this, I've opted to create a new directory for each track I'm using. 因此,我选择为正在使用的每个音轨创建一个新目录。

Thanks! 谢谢!

There are several things you can do. 您可以做几件事。

Probably the best thing is to attach additional work trees to the repo. 最好的办法是将其他工作树附加到仓库中。 This avoids duplicating the database that contains project history. 这样可以避免复制包含项目历史记录的数据库。 It avoids having to keep two sets of refs in sync. 它避免了必须保持两组引用同步。 It's generally the way I would recommend to keep multiple versions concurrently checked out. 通常,这是我建议同时保留多个版本的方法。

So I have master checked out, and I want to check out a branch named other-version as well: 所以我已经检出master了,我也想检出一个名为other-version的分支:

git worktree add /path/to/new/working/directory other-version

See https://git-scm.com/docs/git-worktree for more info on linked work trees. 有关链接的工作树的更多信息,请参见https://git-scm.com/docs/git-worktree

If for some reason this doesn't meet your needs, you can create a second clone. 如果由于某种原因这不能满足您的需求,则可以创建另一个克隆。 You can either clone from the origin a second time, or you can clone from the local copy you already have. 您可以从原点第二次克隆,也可以从已经拥有的本地副本进行克隆。 (Cloning from the local means that by default you push and fetch from one local repo to the other, which could be good or bad. An advantage of cloning locally is that git may be able to avoid duplicating the database through the use of links.) (从本地克隆意味着默认情况下,您可以将一个本地存储库推入另一个本地存储库,这可能是好事也可能是坏事。本地克隆的好处是git可以避免使用链接来复制数据库。 )

If you don't want the locals to be interrelated, but you don't want to re-clone the large repo from the remote, you could 如果您不希望本地用户相互关联,但又不想从远程重新克隆大型仓库,则可以

cd /path/to/repo/parent/dir
git clone file://localhost/path/to/repo/parent/dir/repo1 repo2
cd repo2
git remote remove origin
git remote add origin url/to/the/original/remote

This would be very similar to just copying the repo on disk per your original question, but I'd recommend this type of procedure instead (mostly for reasons of paranoia). 这与仅根据您的原始问题在磁盘上复制存储库非常相似,但是我建议使用这种类型的过程(主要是出于偏执狂的原因)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM