从我的 git 服务器签出/克隆多个分支

checkout / clone multiple branches from my git server

我的 git 服务器上有这个场景:

git branch -a

给出输出:

  common_data
* master
  shared_data

如何在 SAME 时间将分支 shared_data 和 common_data 检出到单独的本地文件夹中:

working_directory/common_data
working_directory/shared_data

在我的本地工作站上?我已经阅读了很多帖子,但不知何故我不知道如何为此使用 work_tree。

谢谢

GT

一种选择是使用 git 的 worktree 功能。您只需要克隆存储库一次:

git clone myserver:myrepo.git
cd my repo

然后您可以使用 git worktree 将分支签出到特定目录中。例如,要将 feature/widget 分支签出到 ../myrepo-widget 目录:

git worktree add ../myrepo-widget feature/widget

或者您的 testing 分支进入 ../myrepo-testing 目录:

git worktree add ../myrepo-testing testing

或者,您可以多次克隆原始存储库:

git clone -b master myserver:myrepo.git myrepo
git clone -b feature/widget myserver:myrepo.git myrepo-widget
git clone -b testing myserver:myrepo.git myrepo-testing

这两种机制在大多数方面都具有相同的功能。第二个选项需要更多存储 space,但大多数 git 存储库都足够小,额外的 space 是无关紧要的。