Show pageOld revisionsBacklinksBack to top This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. # IT:AD:Posh-Git:HowTo:Install # * [[./|(UP)]] * See also: * [[IT/AD/Git/HowTo/Install]] ## Process ## <wrap tip> 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. </wrap> #### 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: * [[IT/AD/Git/HowTo/Install]] #### Installing using PSGet ### Ensure [[IT/AD/PSGet/]] is installed: <sxh powershell> (new-object Net.WebClient).DownloadString("http://psget.net/GetPsGet.ps1") | iex </sxh> Use PSGet to install `Posh Git` <sxh powershell> Install-Module posh-git </sxh> 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/]]: <sxh powershell> #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 </sxh> 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: <sxh powershell> # Load SSH agent utils . (Resolve-Path ~/Documents/WindowsPowershell/Modules/posh-git/profile.example.ps1) </sxh> 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/]] <sxh powershell> 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." </sxh> The result is that, as [[IT/AD/SSH-AGENT/]] is working, [[IT/AD/SSH-ADD/]] will work. ## Resources ## * https://github.com/dahlbyk/posh-git * http://psget.net/ * https://dillieodigital.wordpress.com/2015/10/20/how-to-git-and-ssh-in-powershell/ /home/skysigal/public_html/data/pages/it/ad/posh-git/howto/install.txt Last modified: 2023/11/04 23:01by 127.0.0.1