如何提交不在 git-worktree 的主分支中

How do I make a commit is not in the master branch with git-worktree

例如,我有一个名称为 "Name" 的存储库。并且在存储库中有两个分支:

如果我对文件夹 "Name" 进行了更改,我得到的命令是:

$ git worktree add ../Name-gh-pages gh-pages

通过这个命令,我得到了两个目录:

如果我对文件夹 "Name" 进行了更改,我得到的命令是:

$ git add .
$ git commit -m "test"

如果我更改了文件夹 "Name-gh-pages",我该如何提交?命令 "git add ." 仅在文件夹 "Name" 中看到更改。命令 "git checkout gh-pages" 在这种情况下不起作用。

更新。 jibe 建议的解决方案。

$ git worktree add ../Name-gh-pages gh-pages

我们现在有两个工作目录。

$ git add .
$ git commit -m "test"
$ git push

我们已致力于 "master" 分支。

$ cd ..
$ cd Name-gh-pages
$ git add .
$ git commit -m "test gh-pages"
$ git push

我们已致力于 "gh-pages" 分支。

正如您所指出的,$ git worktree add ../Name-gh-pages gh-pages 您在 gh-pages 上的修改在 Name-gh-pages 文件夹中被跟踪。您只需进入 Name-gh-pages 即可进行修改、提交和推送。但是你不能有 2 个链接的存储库跟踪同一个分支,这就是为什么你不能从 Name 文件夹中检出 gh-pages 的原因。