0
1

WindowsでGitコマンド補完を有効にする方法

Posted at

はじめに

 WindowsのPowerShellで、Gitコマンドの補完を有効にする方法を紹介する。Visual Studio CodeのターミナルでもGit補完が有効となる。

動作確認環境

  • Windows 10 64bit
  • PowerShell

方法

 Git自体は既に導入されているものとする。Gitは、インストーラから簡単に導入可能。
 Git補完するために、posh-gitというツールを利用する。posh-gitは、PowerShellでGit補完を有効にするためのツールである。

  1. 管理者権限でPowerShellを開く

  2. 下記コマンドでposh-gitをインストールする
    現在のユーザのみインストールする場合

    Install-Module posh-git -Scope CurrentUser -Force
    
  3. PowerShellのプロファイルに以下をposh-gitを有効にする設定を追加する

    1. プロファイルの場所を確認する

      $PROFILE
      

      以下のようなパスが取得できることを確認する。

      C:\Users\{username}\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
      

      もしプロファイルが存在しないエラーとなる場合は、下記をコピーして現在ユーザのプロファイルを作成する。

      if (!(Test-Path -Path $PROFILE)) {
          New-Item -ItemType File -Path $PROFILE -Force
      }
      

      PowerShellのプロファイルの詳細は以下を参照。

    2. メモ帳などで上記プロファイル(Microsoft.PowerShell_profile.ps1)を開いて、下記設定を追記する

      Import-Module posh-git
      
  4. PowerShellを再起動して、Gitコマンド補完が有効になっていれば成功

まとめ

 WindowsでGitコマンド補完を有効にする方法を紹介した。Visual Studio Codeのターミナルでも有効になるため、Windows上でのプログラミング開発の効率化に役立つ。

参考

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