# Git需要知道worktree在哪里,用--work-tree来指定
# 将在第3章详细介绍此命令
git --git-dir=the-repo.git --work-tree=default-tree status
# On branch master
#
# No commits yet
#
# nothing to commit (create/copy files and use "git add" to track)
git --work-tree=default-tree status
# fatal: not a git repository (or any of the parent directories): .git
cd default-tree
git status
# On branch master
#
# No commits yet
#
# nothing to commit (create/copy files and use "git add" to track)
git -C default-tree status
# On branch master
#
# No commits yet
#
# nothing to commit (create/copy files and use "git add" to track)
git -C the-repo.git symbolic-ref HEAD
# refs/heads/master
git -C the-repo.git status
# fatal: this operation must be run in a work tree
# 删掉.git文件
rm default-tree/.git
# worktree里面的.git不再是文件了,它就是repo!
mv the-repo.git default-tree/.git
# 检查一下:
git -C default-tree symbolic-ref HEAD
# refs/heads/master
git -C default-tree status
# On branch master
#
# No commits yet
#
# nothing to commit (create/copy files and use "git add" to track)
git -C default-tree/.git symbolic-ref HEAD
# refs/heads/master
# 下面这个命令依然报错,原因同上
git -C default-tree/.git status
# fatal: this operation must be run in a work tree
# 特别注意此处的git-dir已经发生变化
git --git-dir=the-repo.git/worktrees/another symbolic-ref HEAD
# refs/heads/another
# 下面这样也可以
git -C the-repo.git/worktrees/another symbolic-ref HEAD
# refs/heads/another
mkdir another-tree
git --git-dir=the-repo.git/worktrees/another --work-tree=another-tree status
# On branch another
#
# No commits yet
#
# nothing to commit (create/copy files and use "git add" to track)
echo "gitdir: $(pwd)/the-repo.git/worktrees/another" > another-tree/.git
git -C another-tree status
# On branch another
#
# No commits yet
#
# nothing to commit (create/copy files and use "git add" to track)