Get Git with PowerShell

If you are creating PowerShell scripts, tools or modules today, you are most likely using Git. What? You’re not? Is it because you haven’t gotten around to installing it? I have some “quick and dirty” PowerShell hacks to help you out on Windows systems. Linux boys and girls already know what to do.

Naturally you could run a search to find the download link for the latest version of Git. Or if you are using Chocolatey you most likely know how to find and install packages. But perhaps you don’t (or can’t) use Chocolatey. That’s ok. PowerShell can make quick work of this task.

My code assumes you are running on a 64bit system. The comments should explain how it all works. When run you’ll get the latest setup executable. I recommend manually installing it so you can configure it as needed.

Related to this you might need a merge conflict tool. I use kdiff3. Here’s similar code to download it.

Again, go ahead and install it manually.

My last git hack is to use PowerShell to get the version. If you have git installed, you can easily run

In Windows you’ll get something like git version But being the PowerShell geek that I am, I wanted to display just the version number. So I used a regular expression to extract the value.

This same code will also work in open source PowerShell on Linux. Although Windows users can also check the registry:

Want to check the latest git for Windows release to know if you need to download? Use this function.


Fun, right? Now there’s no excuse for setting up git on your Windows desktop.

3 thoughts on “Get Git with PowerShell

  1. The frustrating part is there are those of us that work at financial institutions and you don’t have the access to do anything like instal apps. Not to mention a lot of sites, and URL’s are blocked. heck I have been an some where WSMan is blocked so I had to do all kinds of workarounds.
    If there were flat file alternatives rather than an app you have to install i may be able to get it and run it. Even then sites you connect to to get scripts, etc, often are blocked. It’s like having your hands and feet bound and then thrown into a pool and told to swim.

    • I feel your pain. I understand the business case for security and all that it might require, but at some point management has to weigh the cost of security with the cost of getting your job done.

Leave a Reply

Your email address will not be published. Required fields are marked *