git の「bareリポジトリ」を作って git worktree のフォルダを全て同じ階層にする

● git の「bareリポジトリ」を作って git worktree のフォルダを全て同じ階層にする

普通に git clone した後で worktree を作ると、mainブランチだけ 別階層になってしまいます。

それを解決するためには、以下の手順で clone します。

1 . bare repositoryを作成

git clone --bare https://github.com/user/myrepo.git
// または 最初にアンダースコアをつけておくのも良いです。( _myrepo.git )
git clone --bare https://github.com/user/myrepo.git _myrepo.git

自動的に リポジトリ名.git というフォルダに clone されます。( ↑ この0だとmyrepo.git )
この時点ではどのブランチもチェックアウトされていない状態になります。

2 . mainブランチのworktreeを作成

git --git-dir=repo worktree add main main
git --git-dir=repo worktree add feature-1 feature-1
git --git-dir=repo worktree add feature-2 feature-2
No.2617
06/06 09:28

edit