Table of Contents

IT:AD:Posh-Git:HowTo:Install

Process

Maybe it's the way the paget at https://github.com/dahlbyk/posh-git is laid out – but it seems that a lot of people don't understand the instructions clearly. What' it's saying is that you have to do two steps before Posh-Git works: * The first step is to install the script, using PSGet or doing it manually. * The second step is to modify the %userprofile%\Documents\Microsoft.PowerShell_profile.ps1 config file to actually invoke Posh-Git when a new IT:AD:POSH is started up.

Prerequisites

The following presupposes that IT:AD:Git was installed right, and that the PATH and HOME IT:AD:Environment Variables have been configured right:

Installing using PSGet

Ensure IT:AD:PSGet is installed:

(new-object Net.WebClient).DownloadString("http://psget.net/GetPsGet.ps1") | iex

Use PSGet to install Posh Git

Install-Module posh-git

Restart your IT:AD:Powershell CLI to see the change in prompt when you CD to a Git repository.

Installing using Chocolatey

If you're going to install it, you owe it to yourself to install it intelligently, using IT:AD:Chocolatey:

#hack setting version due to: http://stackoverflow.com/a/29305866
choco install git.install -y -version:"1.9.5.20150114"  -params:'"/GitAndUnixToolsOnPat"'
choco install poshgit -y

Once installed, when you cd to a git directory, the prompts will change, as well as the Git be able to automatically start the SSHAGENT, etc.

Modify the Microsoft.PowerShell_profile.ps1 file

Edit the %userprofile%\Documents\Microsoft.PowerShell_profile.ps1 file so that it invokes the the example Posh-Git profile script within the directory where Posh-Git was installed.

There are a couple of examples of really fancy profile scripts out there – but Posh-Git make it easy.

My file is not much more complicated than the following:

# Load SSH agent utils
. (Resolve-Path ~/Documents/WindowsPowershell/Modules/posh-git/profile.example.ps1)

It in turn is finding the profile.example.ps1 which is ensuring IT:AD:SSH-AGENT is starting up every time you open a new IT:AD:POSH

Push-Location (Split-Path -Path $MyInvocation.MyCommand.Definition -Parent)
# Load posh-git module from current directory
Import-Module .\posh-git
# If module is installed in a default location ($env:PSModulePath),
# use this instead (see about_Modules for more information):
# Import-Module posh-git
# Set up a simple prompt, adding the git prompt parts inside git repos
function global:prompt {
    $realLASTEXITCODE = $LASTEXITCODE
    Write-Host($pwd.ProviderPath) -nonewline
    Write-VcsStatus
    $global:LASTEXITCODE = $realLASTEXITCODE
    return "> "
}
Pop-Location

# My custom changes:
#Start-SshAgent -Quiet
Start-SshAgent
echo "Posh-Git Initiated."

The result is that, as IT:AD:SSH-AGENT is working, IT:AD:SSH-ADD will work.

Resources