LoginSignup
1
0

GUIツールから仮想環境とGitHubを連携しようとしたら苦戦した話

Posted at

環境

  • Windows11
  • wsl(Ubuntu)
  • Git 2.25.1
  • Soucetree
  • Gitドドド初心者

発生したこと

Soucetree経由でGitHubからUbuntu内sunaba01ディレクトリにリポジトリをクローンしようとしたら以下のエラーが発生

'git status' がコード 128 で終了しました: fatal: detected dubious ownership in repository at '//wsl.localhost/Ubuntu-20.04/home/***/sunaba01'
To add an exception for this directory, call:

	git config --global --add safe.directory '%(prefix)///wsl.localhost/Ubuntu-20.04/home/***/sunaba01'
 (\\wsl.localhost\Ubuntu-20.04\home\***\sunaba01)

image.png

原因

git 2.35.2から導入されたsafe.directoryの影響らしい

解決方法

筆者の例であるが、以下のコマンドを試したら解決したしなかった("再発"にて記載)

git config --global --add safe.directory "'%(prefix)///wsl.localhost/Ubuntu-20.04/home/*'"

個別ディレクトリを毎回設定するのが面倒だったので、homeディレクトリ以下は全部許可する設定でsafe.directoryに登録

この際、パス指定を'%(prefix)///wsl.localhost/Ubuntu-20.04/home/*'とシングルクオーテーションだけにしてしまうとうまくいかなかった

確認

safe.directoryを設定後、ちゃんと設定できているか確認する

$ git config --global -l

color.diff=auto
color.status=auto
color.branch=auto
safe.directory=%(prefix)///wsl.localhost/Ubuntu-20.04/home/*
safe.directory='%(prefix)///wsl.localhost/Ubuntu-20.04/home/*'

safe.directory='%(prefix)///wsl.localhost/Ubuntu-20.04/home/*'があればOK

所管

Gitを触るのが初心者だったため、バージョン依存ではなく仮想環境依存のエラーだと思い原因特定までに苦戦した。
エラーメッセージを検索したらあっさり出てきたので、後学のために本記事を残す。

再発

解消したと思ったらエラー再発。
原因が「仮想環境側のGit」ではなく「仮想環境にアクセスしようとする、Windows側のGit」だったので、Windows側のGitのsafe.directoryを設定。
今回は自分しか使用しないので全ファイル許可の設定で記述する。
(Windows側のCUIはPowerShellを使用)

git config --global -e

config内

[safe]
        directory = *

※仮想環境側のsafe.directoryは削除して問題なかった

これでWindows側に入れたGit GUI経由でGitHub管理に成功。
Twitterで悲鳴を上げていたら助けてくれたFF内有識者に感謝。

1
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
1
0