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.
- install MsysGit
- Add the installation folder to the Environment-variable PATH (C:\Program Files (x86)\Git\cmd; C:\Program Files (x86)\Git\bin)
- start Windows PowerShell as Administrator
- allow script execution by entering ‘Set-ExecutionPolicy RemoteSigned’
- download the Git-PowerShell module via: ‘(new-object Net.WebClient).DownloadString(“http://psget.net/GetPsGet.ps1“) | iex’
- install this module via: Install-Module posh-git
- navigate to the install folder of the posh-git-module: cd C:\Users\__user_name__\Documents\WindowsPowerShell\Modules\posh-git
- run the installation: install.ps1
- close you PowerShell session
- 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
- 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
- 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):
- 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:
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.
- PowerShell-module posh-git info: https://github.com/dahlbyk/posh-git
- a similar implementation exists for Mercurial, named posh-hg: https://github.com/JeremySkinner/posh-hg