コガネブログ

平日更新を目標に Unity や C#、Visual Studio、ReSharper などのゲーム開発アレコレを書いていきます

【Unity】Unity 起動時に「An error occurred while resolving packages: No 'git' executable was found.」と表示される場合

はじめに

f:id:baba_s:20210823140412p:plain

Unity プロジェクトを開く時に

f:id:baba_s:20210823140339p:plain

Unity Package Manager Error

An error occurred while resolving packages:
  Project has invalid dependencies: 
    xxxx: No 'git' executable was found.
Please install Git on your system and restart Unity and Unity Hub

上記のエラーが発生する場合、環境変数の Path に git.exe のパスを通して
Windows を再起動すればエラーが発生しなくなります

この記事では SourceTree を使用している場合の
詳細な対応方法を紹介していきます

検証環境

  • Windows 10
  • Unity 2020.3.13f1
  • SourceTree 3.4.5
  • Git 2.30.2

手順

f:id:baba_s:20210823140528p:plain

Windows のスタートメニューから「コマンドプロンプト」を起動して

f:id:baba_s:20210823140531p:plain

コマンドプロンプトが開いたら「git」と入力して Enter を押します

f:id:baba_s:20210823140534p:plain

上記のように「'git' は、内部コマンドまたは外部コマンド~」と表示されたら次に進みます

f:id:baba_s:20210823140628p:plain

SourceTree を開いて「ツール > オプション」を選択して

f:id:baba_s:20210823140631p:plain

「Git」タブを選択して、赤枠の箇所のパスをメモしておきます(後で使います)

f:id:baba_s:20210823140634p:plain

Windows のスタートメニューから「環境変数を編集」を開いて

f:id:baba_s:20210823140637p:plain

「Path」の項目を選択した状態で「編集」を押して

f:id:baba_s:20210823140640p:plain

「新規」を押して

f:id:baba_s:20210823140643p:plain

先ほど SourceTree でメモしたパスを入力します
この時、末尾の「\git.exe」は入力する必要はありません
入力できたら「OK」を押します

f:id:baba_s:20210823140646p:plain

もう一度「OK」を押します

f:id:baba_s:20210823140528p:plain

ここまでできたら、Windows のスタートメニューから「コマンドプロンプト」を起動して

f:id:baba_s:20210823140531p:plain

コマンドプロンプトが開いたら「git」と入力して Enter を押します

f:id:baba_s:20210823140649p:plain

そして、上記のように英語で色々表示されれば問題ありません
もしもまだ「'git' は、内部コマンドまたは外部コマンド~」と表示される場合は
環境変数に設定したパスに不備がないかを確認してみてください

最後に Windows を再起動してから Unity プロジェクトを開くと
エラーが発生しなくなったことを確認できると思います