Posh-git installation

Posh-git is a set of PowerShell scripts which provide Git integration. This post describes how to install posh-git on Windows 10 Enterprise without any proxy.

The easiest way to install posh-git is using Chocolatey, which is a Machine Package Manager – tool like apt-get – but for Windows. Chocolatey can be installed based on description on project page https://chocolatey.org/ 

So in order to install Chocolatey open Command Prompt (cmd.exe) in administrative mode, paste and run the following command:

@powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((new-object net.webclient).DownloadString(‚https://chocolatey.org/install.ps1’))" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin

After installation is finished screen should look like this and after seeing this message restart Command Prompt in order to be able to use choco command:

chocolatey installation done - warning

After restart run ‘choco install poshgit’ command.

During installation confirm all the questions and you should see output as below:

poshgit installation

3rd install

4th screen

During installation on Windows 10 PowerShell acted like it was freezed so don’t hesitate to use enter key in order to see the progress.

When installation is finished run PowerShell as an Administrator. After loading prompt you can see error as in the picture below:

5th powershell error

In order to get rid of this message (and load correctly PowerShell profile) you must change execution policy in PS, e.g. using cmdlet Set-Executionpolicy –ExecutionPolicy Unrestricted

After PowerShell restart this error should disappear. However there is one more step to complete for posh-git to work correctly. As for day of this post creation there’s known error in Microsoft.PowerShell_profile.ps1 which causes posh-git not fully functional, so this file content should be updated. Microsoft.PowerShell_profile.ps1 file is placed in C:\Users\your_user_name\Documents\WindowsPowerShell folder.

Replace file content with the following:

# Load posh-git example profile
. ‚C:\tools\poshgit\dahlbyk-posh-git-fadc4dd\profile.example.ps1’

Rename-Item Function:\Prompt PoshGitPrompt -Force

function Prompt() {if(Test-Path Function:\PrePoshGitPrompt){++$global:poshScope; New-Item function:\script:Write-host -value "param([object] `$object, `$backgroundColor, `$foregroundColor, [switch] `$nonewline) " -Force | Out-Null;$private:p = PrePoshGitPrompt; if(–$global:poshScope -eq 0) {Remove-Item function:\Write-Host -Force}}PoshGitPrompt}

Save file and then restart PowerShell – happy work with Git using PowerShell.