Use Git with Pleasure from All Your PowerShell Consoles

October 13th 2014 Git PowerShell ConEmu

Since I've first installed ConEmu after reading Scott Hanselman's excellent blog post about it, I've been using it for all my console needs. Even the command prompt improvements in Windows 10 haven't really excited me all that much. There was an exception, though. I've never really made the effort to make Git work in my system command prompt. SourceTree seems to cover most of my needs, when interacting with Git. When I really needed to use it from the command line, I settled with its embedded terminal support. Now that I've finally decided to take care of this, I collected all the steps I took in this blog post for future reference. I assume it might prove useful to others, as well.

Since SourceTree comes with its own embedded installation of Git, the first step was actually installing standalone Git. I kept most of default options in the installer, except for the PATH variable - I wanted Git to be included in the path so that I could use it from everywhere.

Use Git from the Windows Command Prompt

This was enough to get Git working in its most basic form, but I really wanted to take it further. As an avid PowerShell user, the next logical step was posh-git to get some prompt and tab completion goodness. The simplest way of installing it is with PsGet. Even if you've never before used the latter, you only need to execute the following commands:

(new-object Net.WebClient).DownloadString("http://psget.net/GetPsGet.ps1") | iex
Install-Module posh-git
. $PROFILE

The last command reinitializes your PowerShell session with the updated profile. After doing that, posh-git complained:

WARNING: Could not find ssh-agent

This happened because during Git installation I decided against polluting my path by adding c:\Program Files (x86)\Git\bin to it. Fortunately there's an easy way to get around that. Just add the following two lines to your PowerShell profile file (type notepad $PROFILE to edit it):

Set-Alias ssh-agent "${env:ProgramFiles(x86)}\git\bin\ssh-agent.exe"
Set-Alias ssh-add "${env:ProgramFiles(x86)}\git\bin\ssh-add.exe"

After saving the changed file and reinitializing the session again (. $PROFILE, remember?) the error was gone.

There was one last thing, I wanted to fix: Git kept prompting me for my password whenever I tried to interact with my HTTPS remotes. Windows Credential Store for Git can help with that. I just downloaded it, executed it, and it worked. The next time Git required my password to access the remote, the following popup was displayed instead of the usual prompt in the console:

Enter Git Credentials

This was the last time I had to enter my credentials. They are now safely stored Windows Credential Store and retrieved from there whenever Git communicates with my remotes. Now, I'm truly satisfied with my setup.

Thanks to Phil Haack, brianary, and Joshua Gall for their posts which where the source for all of the above.

Get notified when a new blog post is published (usually every Friday):

If you're looking for online one-on-one mentorship on a related topic, you can find me on Codementor.
If you need a team of experienced software engineers to help you with a project, contact us at Razum.
Copyright
Creative Commons License