How I Accidentally Discovered How To Use Git inside Powershell

In the course of my forays into the world of programming (or rather, coding) I have had cause to learn how to use Git for version control (thank you, Linus Torvalds, for this great tool!). Although some of the IDEs that I use (RStudio for R; Visual Studio for C++) have some form of Git integration, I discovered that it’s much better to do my commits, branching, pulling and pushing using the command-line interface (CLI).

Besides all this, I have over time gotten tired of having to learn how to use my graphics user interface (GUI) with every major upgrade, so I just returned to the basics (I learnt computing with MS-DOS) and have settled down with using Windows Powershell to interact with my computer’s operating system. Therefore, whenever I wanted to run Git, I would this (note that anything before the ‘>’ symbol is included in the prompt, while the text on the right hand side is supplied by the user)

PS C:UsersAdmn>
PS C:UsersAdmn> Start-Process .DownloadsMinGWGitgit-cmd.exe

Alternatively, rather than use the cmdletStart-Process‘, one could use the alias ‘start‘ and get the same result.
This command opens up Git CMD in a new window. Optionally, one could type git-bash.exe if one wants to use Git Bash, but since I prefer Git CMD, I will focus on that in this post.

I found opening this new window to be cumbersome, since I could as well open the application through the Start Menu by hitting ‘Win-key’ and typing the search term ‘git’. I looked online to see whether there was anything on Git integration with Powershell, but came up empty.

One day, as I was trying to open Git via Powershell, I committed a typo and hit the jackpot! Here is what I discovered: I could open Git CMD right inside Powershell, carry out all the operations I wanted and then exit without having to terminate my Powershell session. This is what to do

PS C:UsersAdmn>
PS C:UsersAdmn> C:UsersAdmnDownloadsMinGWGitgit-cmd.exe

Note that there is no cmdlet in this instruction. What happens next is that the prompt changes from

PS C:UsersAdmn>



This means that, effectively, this has ceased to be a Powershell window, but has been transformed to a regular Command Prompt environment. If you navigate to any directory that is a Git repository, the appropriate commands like git status work just fine – which is impossible if you’re using Powershell. When you’re done and your want to return to Powershell, just run exit at the prompt and it will change to the ‘PS’ prefixed state.

Note that for some silly reason, I installed Git in my ‘Downloads’ folder. On another machine, I have it installed in the right place – i.e. Program Files – and when I carried out the above operations using the appropriate file path, the result was the same. I had stumbled upon Git integration in Powershell!

I tried this out with v2.0 and v5.0, so for all intents and purposes, this should work with any Windows machine that has Powershell installed .


One thought on “How I Accidentally Discovered How To Use Git inside Powershell


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

You are commenting using your 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