A better Git-commandline by integrating Git with PowerShell

For the people who never heard about Windows PowerShell; a short introduction:

PowerShell is available since Windows XP SP2. It gives you the full power of .NET, WMI and COM all from a command line and it’s compatible with ‘old’ DOS-based commands and many Unix-style commands.

It combines command-line speed, the flexibility of scripting, and the power which an administrator needs. A (small) extract of others things you can do with PowerShell: controlling services, computer, Windows-servers, VMWare, Exchange-server, IIS, Office, databases, XML, Web, … It can even replace some utilities of the Sysinternals-suite.

PowerShell has a steep learning curve, but it’s possibilities are endless.

In Windows 8.1 it even replaces by default the command prompt (but If you’re old school you can still set it back to the classical prompt).

This tutorial describes how to extend the possibilities of PowerShell even more by integrating Git-support in it.

Set-up steps:

  1. install MsysGit
  2. Add the installation folder to the Environment-variable PATH (C:\Program Files (x86)\Git\cmd; C:\Program Files (x86)\Git\bin)
  3. start Windows PowerShell as Administrator
    PowerShell Start menu
  4. allow script execution by entering ‘Set-ExecutionPolicy RemoteSigned’
  5. download the Git-PowerShell module via: ‘(new-object Net.WebClient).DownloadString(“http://psget.net/GetPsGet.ps1“) | iex’
  6. install this module via: Install-Module posh-git
  7. navigate to the install folder of the posh-git-module: cd C:\Users\__user_name__\Documents\WindowsPowerShell\Modules\posh-git
  8. run the installation: install.ps1
  9. close you PowerShell session
  10. start a new PowerShell session and navigate to a folder with a repository and you will get a screen like this:
    Next to the folder name it shows the name of the current branch
    Once a PowerShell-session is inside a repository it all Git-commands (add, clone; push, …) can be executed here
    PowerShell Git repo unchanged
  11. Now I added two files and the prompt changes become like this:
    Next to the branch there are the amount of new files, modified files, removed files and conflicting files.
    So, in this example you can see “+2” which means two new files
    PowerShell Git repo 2 new files
  12. Great, you might say, but if I’m working in several folders I need to opens several PowerShell-sessions. Aha, when we don’t start up the PowerShell-script window, but the PowerShellISE (Integrated Script Environment).
    When you open it for the first time it looks like this (an IDE where the main pane is a script editor with colour coding and code completion, on the right a command list with access to help etc., and on the bottom an interactive pane):
    PowerShellISE clean
  13. When you close the Script Pane and the Show Commands Add-On only the console remains. Then you can open several console sessions at the same time by pressing CTRL-T
    The result can look like this:
    PowerShellISE Git
    This shows a PowerShell-session with two tabs, Git integration, history notification (for even easier access to the history as standard PowerShell/command-prompt) and a custom theme for easier reading.

I would recommend everyone to install the Git-extension for PowerShell and you’ll experience the real power of it. It removes completely the need for other command lined utilities like Git Bash.



Author: jdhnet

Software Tester and Web Developer

3 thoughts on “A better Git-commandline by integrating Git with PowerShell”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.