Wiring Up Posh Git Using GitHub for Windows Installation
I have been using this method of wiring up posh git for a couple years now. And every time I have to setup a new box I have to go digging around to remember exactly how I set it up. So creating a post as a form of self documentation.
First, install GitHub for Windows. Best option use a boxstarter script. Next best option, install it vai chocolatey with this command choco install githubforwindows
. Worst case scenario, install it via the website.
Next, ensure you have a PowerShell profile by running this command Test-path $profile
. If that command returns false, you don't have a profile. So, create one with this command New-item –type file –force $profile
.
Finally, open your PowerShell profile with atom $profile
and add the following script.
(Get-Host).UI.RawUI.BackgroundColor = 'Black'
(Get-Host).UI.RawUI.ForegroundColor = 'Green'
cls
echo "Calculating the ultimate answer to life, the universe and everything..... Plz wait..."
. $env:LOCALAPPDATA\GitHub\shell.ps1
. $env:github_posh_git\profile.example.ps1
$env:Path = "$env:Path;.bin"
cd c:\src
echo "Answer: 42"
Now fire up a fresh PowerShell instance and check your install with git --version
.
Not working? Did you forget to add Update-ExecutionPolicy RemoteSigned
to your boxstarter script? Working at a draconian client that has some silly security forced on your dev box that won't allow boxstarter to work correctly? Throw a Set-ExecutionPolicy RemoteSigned
at your administrator elevated PowerShell prompt.
Still not working? Sorry dude, better attack that with some google-fu.
Bonus: Want to be ultra hipster and use git-flow as well? We can do that.
First you need to download getopt.exe
from the util-linux package; grab the binaries and dependencies zip files.
Next, open the binaries archive and copy getopt.exe
in the bin directory to the bin directory located at $env:LOCALAPPDATA\GitHub\Portab~1
. Also, open the dependencies archive and copy libintl3.dll
and libiconv2.dll
in the bin directory to the same location.
Next, switch to the GitHub root directory with cd $env:LOCALAPPDATA\GitHub
. And clone the git-flow repository git clone --recursive git://github.com/nvie/gitflow.git
.
Finally, switch to the gitflow directory with a cd gitflow
and run the msysgit-install
script with the location as a paramter like so .\contrib\msysgit-install.cmd $env:LOCALAPPDATA\GitHub\Portab~1
.
You should now be able to test your git-flow installation with a git flow help
. Oh and here is a cheetsheet for using git-flow.
TODO: Convert this manual process into a tiny PowerShell script and hook it into the profile. Here is part of the solution; check the last code block.