git and github part 2

In part one of these series on version control we have seen the basics that are needed to get started with git and to setup version control locally in our environment. In this article, we will go a step further in the learning process and tackle version control on line, and especially on how to use github powershell projects.

This becomes particullarly needed if you are working on infrastructure as code (with technologies such as Desired State configuration) and want to contribute by sharing your own custom ressources, or fix issues on the open sourced resources that Microsoft has made available on Github. Or simply because you have github account, and want to save your powershell code online, on the github platform.

Since All the DSC ressources from Microsoft are opened sourced, it becomes important to know how to work on github. This is specefically true since github is where Microsoft stores their PowerShell DSC resources.

Where do I start to work with github powershell?

We will break this in two main parts:

  1. Create our own repository. Add and commit code to it.
  2. How to fork an existing repository. Add modifications to the code locally, and push that code back to the original writter by making a pull request (Which will be part 3 of this series).

You will see, this is noting to fancy actually.

Be sure to logged in with your Github account. If you don’t have one yet, you can create one here.

Creating our first repository on github powershell and the GUI:

Using a GUI to create a repository on github powershell:

Using the normal web browser is the most easiest thing you can dream off. Follow these simple steps and you will have your repository up in the cloud in no time!

create a github git repository powershell

OMG ! He is so cute!!

 

On the next screen follow these simple steps (Everything is pretty straight forward)

create a github git repository powershell 2

 

 

The readme file is the text that the user will see first when he access your repository on github. Once it is generated, you generally want to put there a short description of what your repository actually contains, some script examples, etc..

 

 

A word on Github repositories:

Github is free. It has no adds and has one way of making revenues: by selling you the possiblities to make your repositories private (not visible to everyone).
Indeed, all the repository that are created, are by default set to public. Which actually means that litteraly the whole world (limited to the people who have a computer and an internet connection) can access your repository. So one thing to keep in mind, is that if you are scripting things for a specefic project that has sensitive data on it: DO NOT STORE IT IN A PUBLIC REPOSITORY

 

There is one important step that should not be omitted: Create a licence file. By default, none is selected, and GITHUB will let you create a repository without a licence if you simply click next. This can be problematic when someone wants to fork your code. Without a licence, he simply cannot do it. The whole purpose of community contribution / sharing is then useless. I generaly go with a MIT licence.

And Tadaaa, there we have our first repository. Easy right?

edit github md file powershell

 

The text that is displayed on the front page can be directly edited by clicking on the readme.md file and then on the next screen, by clicking the little pencil on the very right of the screen. I would recommend you change that right away, with a descrption of what the repository is going to contain. It is a good exercice to that at first, it will help you keep your repositories clean, and organised. And people who are interested in your work will save time in order to understand what your code is intended to do. (which can also be helpfull to you, after some time off on another project for example).

How to clone a github repository using powershell?

In most common cases, we create our code on our workstation (or a specefic server perhaps), with the code beeing somewhere locally. Now that our repository that will host our code resides on git hub, we will have to make a copy of that repository somewhere local where we can add scripts and other various files to it. To do that local copy of our remote github repository using powershell, we will need to ‘clone’ our repository.

For that you will have to have git installed (I also recommend Posh-Git) and you will have to get the URL to your repository. Easy! Github actually has thought of that, and there is a button called “copy to clipboard” that will copy the link right into your clipboard simply by clicking on it.
clone github repository with powershell

With that information in our clip board, open a powershell command prompt, and navigate to the folder were you would like to have your code set locally (There will always be a folder created with the name of as your repository, so Choose a generic name for your root folder).

To clone your github powershell repository, use the following command:

clone github repository with powershell 2

Once we have our repository present locally, we can start to add files, scripts, folders, code etc..to it. For the purposes of this example on how to use github powershell, I will first create a simple file called PowershellDistrict.ps1 and ad just a few lines of text in it.

The second step, will be to add the file to our github powershell repository (notice how posh-git already changes the prompt information)

and lastly I commited the file to our repository:

add files to github and commit powershell

 

Until here, there is nothing new to what we have already done before during part 1 of this blog series. This time we need to tell our remote repository that we have some information that we want to push over to him. For that, we will be using the push command:

Supply your crendetials, and thats it!

push files to github with powershell

 

if we go a check on github, we can see that our file is now present on github.com 🙂

github powershell

Digg more into github powershell, and git in general:

For the (lucky?) ones that understand french, and love the Quebecois accent, I really recommend to have a look at this video from Dominic –> https://www.youtube.com/watch?v=5IcYILdejs8

If you want to configure your ISE to work with git, you can follow this blog post of Mike F.Robbins –> http://mikefrobbins.com/2016/02/09/configuring-the-powershell-ise-for-use-with-git-and-github/

By | 2016-10-19T21:00:12+00:00 August 21st, 2016|git, github, PowerShell|0 Comments

About the Author:

Stéphane is a dynamic and passionate Cloud and datacenter Microsoft MVP since. He is the founder of the Basel PowerShell user Group (BPUG), the co-founder of the French Speaking PowerShell UserGroup (FRPSUG), author, blogger, and received the community award "PowerShell Hero" from PowerShell.org. Stéphane has implemented microsoft infrastructure solutions in various countries of Europe and is currently working in Basel / Switzerland. Stéphane help his clients to reduce their global infrastructure costs by implementing Microsft infrastructure solutions by combining great products such as System Center, Windows Server, with heavy automation using Windows PowerShell. Stéphane loves languages, Belgium beer, French cheese and French Wine. If any of these topics are of your interest, don't hesitate to come and say hi.

Leave a Reply

%d bloggers like this: