Try   HackMD
tags: Git

GitBash 導入後にコマンドパスを通す

「HTML/CSS講座」のWindowsユーザ向けの補助資料です。

手順

  1. 環境変数設定画面を開く
  2. システムの環境変数にgit.exeまでのパスを追記

現状を確認

cmdもしくはPowerShellを開いて、以下のコマンドを実行します。

git # もしくは git --version

※ VSCode のターミナルから開いてOK!
※ GitBash からの実行ではないことに注意!

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

引用:https://nikunimame.com/check-path/

環境変数設定画面を開く

[Windowsキー]+[R] の同時押しで、「ファイル名を指定して実行」ウィンドウを開き、sysdm.cpl と入力します。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

OKをクリックすると、「システムプロパティ」ウィンドウが開くので、詳細設定タブを選択します。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

右下の「環境変数(N)」をクリックして「環境変数」ウィンドウを開きます。

システム環境変数から「Path」を探し出し、選択します。
その状態で、右下の「編集(I)」をクリックします。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

「環境変数名の編集」ウィンドウが開くので、「参照(B)」をクリックします。
GitBashのgit.exeが格納されているフォルダパスが分かる人は「新規(N)」で手入力してもいいですが、タイポを防ぐために参照からやるのがいいです!

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

私の場合、「C:\Program Files\Git\bin」に git.exe がインストールされているので、「フォルダーの参照」ウィンドウでそこまでたどっていきます。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

「bin」フォルダを選択して「OK」をクリックします。
環境パスが追加されます。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

追加出来たら、すべてのウィンドウを「OK」を押して閉じます。

PCを再起動

環境パスを新たに追加したので、PCを再起動しましょう。

VSCodeのターミナルからコマンドを叩く

ターミナルに以下を入力。
バージョン確認コマンドです。

git --version

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

うまく環境パスが通っていない場合は、最初と同じエラー画面が出現します。

今回はCMDで実行しましたが、PowerShellでもOKです。

うまくいかなかった人へ

以下の項目を疑ってみてください。

  • 環境パスが正しくない
  • PCを再起動していない

それでもうまくいかない時は、講座主催者に連絡してください。

参考記事