PowerShell git: The beginning! I am writing this blog post from the airport / air plane heading back to Basel. I was at the Powershell summit (#pshsummit) in Stockholm and I really had a GREAT time!
Not only I could see my old #powershell friends, but I got the occasion to meet a lot more! The feeling of beeing part of a community grows each time I have an interaction with anybody who does something related to #powershell over the internet. But is multiplied by 400 when you meet these same people physically! It is just great!
The sessions were great, and I will be blogging about a few a them for sure in the near future, but one topic that I could actually get covered here in the airplane, was how to use version control with powershell. With some of Microsoft’s code beeing open sourced, there has been a real shift in Windows world towards version control.
The topic has been covered in the following sessions:
- Microsoft PowerShell team –> session title: Community + Powershell -eq ‘Achieve more’
- Simon Wahlin (@SimonWahlin) –> Session title: I am not a developper.Or am I?
While the first one was more on how the Microsoft PowerShell team now works on in an open source world, they explained us how we could make feature requests, file bugs, and even troubleshoot our own ones, and send pull request once we have corrected any potential bugs.
The second session present by Simon was really a session from learn git in an hour. It was really great, and I really learned a lot. I actually learned so much, that it got me totaly hyped up. I immediatly downloaded the module (see below on how to do that) and started to work with it.
There is to much blabla for you and want to get straight to the learning point? Scroll down to part 1, for the basics. Or go directly to the bottom at step 10 to have a nice overview in a mind map format on how to start to use powershell git (posh-git) for Windows.
If you write a lot of code, and if you are NOT using any software to organize your changes in your code, you are loosing time and version control will change your life!
Some people might say “Yeah, I am not a developper” or “I dont want to do that, I am just a scripter”. But as Simon mentionned: If you are writing code that is used in production, you must take responsibility like a developper.
And to complete with a quotation from Steve Murawski (@steveMurawski) “If you write code every day, you are developer: Get over it!”
I would like to add and complete, that times have changed. A few years back there was this kind of strange competition between developers and IT Pros. Each of us would make silly jokes about the the other ones.
But today the line that separated our daily tasks has become so thin, close to unexisting, that that competetion is useless, and looks like and old image in black and white from the past. Today, we talk about Devops, which is how we join our forces to make us biger and stronger. One of the bridges that is used by IT pros to link to the developers, is without any doubt “PowerShell”
No matter what language we use to write code. If it is a scripting language or a lower level programming language: If code is used in production, having it stored in simple folders, is not enough anymore.
Why should I care about version control?
You can deliberatly choose not to care. I think that as long as everything works fine, nobody will force you to change your habits. But, when you loose code that was in production, and that you loose hours of work, or if you break something in production by updating a script, and cannot roll back (or dont know how), that’s the moment when you will hate yourself for not having invested time in updating your skill set, and adding version control with GIT for powershell in it.
The learning curve to get you started will be small, and easy. It is afterwards, during your code writing process, that you will need to change a few of your habits. It is time to get structured!
If you are decided to get the powershell git knowledge, keep reading!
0) what are the powershell git / posh-git prerequisites ?
Ok great, you are still here!
Setting up the prerequisites, will take you 5 minutes. Simply follow the 5 steps I have highlighted for you in the mind map below, and everything should roll smoothly!
Each powershell git prerequisit step is detailed here under:
a) Download and install git.
You can download git directly from the official website here.
You can also download and “Github desktop“, which comes with a posh powershell prompt called ‘Git Shell’. Which you will need to use if you want to have the git coloring syntax in your prompt.”
b) Install posh-git
To start, you will want to get the binaries to manage git localy on your authoring machine. PowerShell 5.0 made that super easy for us. Open a command prompt with elevated priviledges and run the following command;
1
|
Find-module posh-git | install-module
|
If you don’t have the cmdlet “Find-Module”, then you are not using PowerShell 5.0 yet. This is ok, but you will need to download Posh-git manually then. You can get it directly from the official git-scm website here.
c) Update your path environment variable
You might have an error message saying you don’t have the %programfiles%gitcmd in your %path% variable.
This might not be necessary for you, but on my machine (Windows 8.1) with Powershell version 5.0 production preview from August, I needed to update the content of my path variable otherwise the git commands refused to work. For that I simply added the following line to my %path% environment
Either add it graphically using Windows + Pause Advanced EnvironmentVariables System Variable
And the following line at the end of your %path% variable (using “;” to separate it from the last line).
%ProgramFiles%gitcmd
Or directly using powershell (you will need to close and reopen your prompt to make the changes take effect) by using the following command:
Leave A Comment