How to use posh-git that comes with GitHub for Windows from custom shell?

强颜欢笑 提交于 2019-12-02 16:47:38
Sergey Aldoukhov

Though @dahlbyk answer did not provide resolution, it still pushed me in the right direction. The problem is, $env:posh-git environment referenced in the Phil's Haack blog post is not defined, so testing it in the PowerShell profile script does nothing.

What works though is running shell.ps1 and profile.example.ps1 from the same script. Here is the recipe for PowerShell noobs like me:

  1. Edit or create Microsoft.PowerShell_profile.ps1 in active user's Documents\WindowsPowerShell folder (create the folder if it does not exist)
  2. Add the following 2 lines:

    . (Resolve-Path "$env:LOCALAPPDATA\GitHub\shell.ps1")
    . $env:github_posh_git\profile.example.ps1
    

From http://haacked.com/archive/2012/05/21/introducing-github-for-windows.aspx, put this in your profile to load posh-git from GitHub for Windows:

# If Posh-Git environment is defined, load it.
if (test-path env:posh_git) {
    . $env:posh_git
}

Following these directions, to install and use Posh-git in powershell do the following:

  1. git clone git://github.com/dahlbyk/posh-git.git to your choice of directory
  2. Permit executing scripts using either:
    1. Set-ExecutionPolicy RemoteSigned
    2. Set-ExecutionPolicy Unrestricted
  3. cd posh-git
  4. .\install.ps1
  5. . $PROFILE

I originally followed directions given in the popular haacked.com tutorial (as pointed out by @dahlbyk and @CB) but had similar issues as the OP.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!