Powershell Source Control: GIT and Visual Studio Online

In this blog post I am going to explain how I manage my Powershell scripts / projects. Let me start with my toolset:

Next we create a new VS Online account. Go to http://visualstudio.com and login with your live account:

After login enter some more details:

Choose Create a Free Account Now under the Accounts Section:

Choose a URL you want to use:

And we have a Visual Studio Online Account. Afterwards I created directly my first project called Hyper-V-Deployment. Choose GIT as version control!

When the project is created and we go to the Code tab you get a message that the repository is empty:

IMPORTANT: If you plan to use Command Line Git Tools (as we need to in this blog) you need to enable basic authentication on your Account. So let’s configure my account for Basic Authentication. Go to your Profile:

Choose Credentials en click on Enable alternate credentials:

Enter new credentials I also like to use the secondary name so it has no relation to my outlook.com email account and other services I use:

Now when the authentication is done, repository is ready, we can start using the new repository. On my DevOps Machine I have installed GitHub and the CLI Tools included:

I open Git Shell :

Let’s start with cloning the new repository to my machine: Git clone https://sysctr.visualstudio.com/DefaultCollection/_git/Hyper-V-Deployment Hyper-V-Deployment You see in my command after the url is specified the new folder name I would like to create under the root from where I started Git Shell.

You get a message that I cloned a empty repository. What seems right to me. When I enter the folder I specified I can create a new file for example:

And edit this new item in PowerShell Studio 2014 (you can also use ISE) :

I created a simple function and saved the file:

When I go back to my shell I can run this command to add the file to my Repository: Git add test.ps1

The reason why you still red +1 is because Powershell Studio uses restore points. The file that is untracked at the moment is my restore point from the test.ps1 file. When I close Powershell Studio 2014 this red +1 is gone. Then I going to commit this: Git commit –m “Test for blog”

Finally I am going to push my repository back to visual studio online:

Now when I log in to VS2013 online I see my file:

And my Comment:

I often got asked how I manage my structure for Scripts. Well this is my personal opinion but as I use the Visual Studio mainly for myself and version control only I created 1 Git Project in VS Online called PoShLib. Underneath I created different kind of folders for different products. I only separated all my Projects and modules in seperate folder as in Powershell Studio 2014 it is easier to define the project folder in the option settings and modules because I construct them in the final state (as it is a copy of my module folder from my Powershell Program Files Directory):