使用 Windows 版 Github 多次克隆同一存储库

问题描述 投票:0回答:2

是否可以使用 Windows 版 Github 多次克隆同一存储库?我问的原因是我想多次克隆 Laravel 框架,对于我使用它的每个项目一次。

git github github-for-windows
2个回答
18
投票

这是可能的,而且很简单

在 git bash 中:

git clone <repo> <directory>
git clone <repo> <directory_2>
.............................
git clone <repo> <directory_N-1>
git clone <repo> <directory_N>

Repo 是你的存储库 URL,所有这些目录[N] 是你想要的目录名称

另外,为什么不将已经克隆的存储库复制到另一个目录呢?


0
投票

@baldrs(多次克隆)接受的答案有效,但并不是人们想象的那样。

Git 有一个名为

worktree
的功能,这就是这里应该使用的功能:

git clone --bare <repo> ./repo.git
cd ./repo.git
git worktree add ../<directory> master
git worktree add ../<directory_2> master
......
git worktree add ../<directory_N> master

这是更好的方法,特别是当它是一个大型存储库时,因为 git 对象数据库仅被克隆一次并且每个工作树都使用相同的数据库。

使用这种方法,如果需要的话单独切换分支是没有问题的,不用担心。

有关详细信息,请参阅 git 文档:https://git-scm.com/docs/git-worktree

© www.soinside.com 2019 - 2024. All rights reserved.