0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

git worktree作業フォルダの関連付け修復

Last updated at Posted at 2025-06-26

worktree作業フォルダの移動や改名

git worktree で作業フォルダを作成している人に向けての記事です。

正しい方法

git worktree add で作成した作業フォルダを移動や改名したい場合

git worktree move old-folder new-folder

とすることで、安全確実に移動・改名できます。

そうはいっても

作業フォルダが入ったドライブの交換や増設、OSの入れ替え等で、

  • git clone で作成した作業フォルダ を移動や改名した
  • git worktreeで作成した作業フォルダを(gitコマンドを介さずに)移動や改名した

このようなケースでは git worktree move コマンドで処置することができず、結果としてworktree作成作業フォルダへの関連付けが失われてしまいます。

なぜなら、clone作成作業フォルダ直下の.gitフォルダ内のgitdirファイルと、worktree作成作業フォルダ直下の.gitファイルが、下記のように相互にパス名を保持して関連付けしているからです。

clone作成作業フォルダ/.git/worktrees/worktree名/gitdir
worktree作成作業フォルダのフルパス
worktree作成作業フォルダ/.git
gitdir: clone作成作業フォルダのフルパス/.git/worktree/<worktree名>

関連付けを修復するには

上記の相互参照を手作業で修正しても修復できるようですが、
以下のコマンドを実行することで、より安全に修復できます。

cd <移動改名後のclone作成作業フォルダ>
git worktree repair <移動改名後のworktree作成作業フォルダのフルパス> 

git公式ドキュメント

END

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?