The legacy command-line terminal on Windows (cmd.exe
) isn’t really capable of a customized Git experience, but if you’re using PowerShell, you’re in luck.
This also works if you’re running PowerShell on a non-Windows platform like Debian.
A package called Posh-Git (https://github.com/dahlbyk/posh-git) provides powerful tab-completion facilities, as well as an enhanced prompt to help you stay on top of your repository status.
It looks like this:
Before you’re able to run PowerShell scripts on your machine, you need to set your local ExecutionPolicy to RemoteSigned (Basically anything except Undefined and Restricted). If you choose AllSigned instead of RemoteSigned, also local scripts (your own) need to be digitally signed in order to be executed. With RemoteSigned, only Scripts having the "ZoneIdentifier" set to Internet (were downloaded from the web) need to be signed, others not. If you’re an administrator and want to set it for all Users on that machine, use "-Scope LocalMachine". If you’re a normal user, without administrative rights, you can use "-Scope CurrentUser" to set it only for you.
More about PowerShell Scopes: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_scopes
More about PowerShell ExecutionPolicy: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-executionpolicy
> Set-ExecutionPolicy -Scope LocalMachine -ExecutionPolicy RemoteSigned -Force
If you have at least PowerShell 5 or PowerShell 4 with PackageManagement installed, you can use the package manager to fetch Posh-Git for you.
More information about PowerShell Gallery: https://docs.microsoft.com/en-us/powershell/gallery/overview
> Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
> Update-Module PowerShellGet -Force
> Install-Module Posh-Git -Scope AllUsers
If you want to install Posh-Git only for the current user and not globally, use "-Scope CurrentUser" instead.
If the second command fails with an error like Module 'PowerShellGet' was not installed by using Install-Module
, you’ll need to run another command first:
> Install-Module PowerShellGet -Force -SkipPublisherCheck
Then you can go back and try again. This happens, because the modules that ship with Windows PowerShell are signed with a different publishment certificate.
To include git information in your prompt, posh-git needs to be imported. To do this automatically, include the import statement into you $profile script. This script is executed everytime you open a new PowerShell prompt. Keep in mind, that there are multiple $profile scripts. E. g. one for the console and a separate one for the ISE.
> New-Item -Name $(Split-Path -Path $profile) -ItemType Directory -Force
> 'Import-Module Posh-Git' | Out-File -Append -Encoding default -FilePath $profile
Just download a Posh-Git release from (https://github.com/dahlbyk/posh-git), and uncompress it to the WindowsPowerShell
directory.
Then open a PowerShell prompt as an administrator, and do this:
> cd ~\Documents\WindowsPowerShell\Module\posh-git
> .\install.ps1
This will add the proper line to your profile.ps1
file, and posh-git will be active the next time you open your prompt.