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

3

23

Installing GitHub for Windows is a nice way to get at once beginner's git Windows app, msysgit and posh-git - but you can only start the git shell with posh-git by calling "GitHub.appref-ms --open-shell".

What I want to do, is to start a console, load powershell, and use posh-git that comes with Github for Windows - but I can't figure a way to load it into the powershell.

Update: I do not want to install Git for Windows separately, since msysgit is already installed.

I was able to make some progress by calling the shell1.ps1 script from AppData\Local\Github folder - and it does let me invoke git. But it does not display the branch I'm in, opposite to the "Git Shell" from GitHub for Windows.

Lactose answered 20/9, 2012 at 0:26 Comment(2)
Does This link help? haacked.com/archive/2011/12/19/get-git-for-windows.aspxHindgut
@Christian - nope, see updated questionLactose
L
56

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
    
Lactose answered 21/9, 2012 at 5:34 Comment(3)
is there a way to prevent it from forcing me to log in on every command?Assize
This approach is also documented in the Git Docs git-scm.com/book/en/v2/…Krug
Here's a shortcut for anyone who wants a Console2 / ConsoleZ tab for Posh-Git. Set the Shell property of your tab to this: %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -NoExit -Command "&{ . (Resolve-Path "$env:LOCALAPPDATA\GitHub\shell.ps1"); . $env:github_posh_git\profile.example.ps1;}"Sisson
R
7

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
}
Reactivate answered 21/9, 2012 at 1:33 Comment(0)
C
3

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.

Cristophercristy answered 27/11, 2015 at 21:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.