Post

Setup PowerShell Git Completion with posh-git

Setup PowerShell Git Completion with posh-git

posh-git is a PowerShell module that integrates Git and PowerShell, providing:

  • Git status summary in the prompt
  • Tab completion for common git commands, branch names, and paths

Installation

1
2
3
4
5
# First-time installation
PowerShellGet\Install-Module posh-git -Scope CurrentUser -Force

# Update if already installed
PowerShellGet\Update-Module posh-git

Add it to your profile:

1
Add-PoshGitToProfile -AllHosts -Force

Restart PowerShell to enjoy git completion.

(Optional) Auto-Install Snippet for $PROFILE

For syncing the profile across multiple devices (e.g., via OneDrive), add this snippet to auto-install/update posh-git:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Check if posh-git is installed, install or update if needed
if (-not (Get-Module -ListAvailable -Name posh-git)) {
    try {
        Install-Module posh-git -Force -Scope CurrentUser
    } catch {
        Write-Host "Failed to install posh-git module. Please install it manually using 'Install-Module posh-git'."
        return
    }
} else {
    $poshGitModule = Get-Module -Name posh-git
    if ($poshGitModule.Version -lt (Get-Module -ListAvailable -Name posh-git).Version) {
        Update-Module posh-git -Force -Scope CurrentUser
    }
}

# Import if not already loaded
if (-not (Get-Module -Name posh-git)) {
    Import-Module posh-git
}
Add-PoshGitToProfile -AllHosts -Force

References

This post is licensed under CC BY 4.0 by the author.