Tag Archives: git

Changes to a PowerShell Module Manifest not viewable in Git

When you make a change to a PowerShell Module Manifest and go to commit those changes in Git, I have observed for some time that it was not possible to see the actual changes in the file because Git was showing it as a binary file. I finally found out why this happens……

Take the following example. I’ve created a module manifest for a module Test with New-ModuleManifest:

Now I make a change to the manifest, say up the version to 1.1

When I go to commit the file, I don’t see what has actually changed in the file. Git reports that it is a binary file:

This is because the output from New-ModuleManifest uses UTF16 for encoding, hence Git sees it as a binary file.

Using the handy encoding functions from here we can check the encoding for the manifest file:

I learnt this from the regular PowerShell community call  where there was a discussion around standardising on the encoding for all cmdlets in PowerShell Core 6. In versions prior to 6 different cmdlets use different encodings types, so it seems like a good opportunity to standardise, particularly with the move to make PowerShell cross-platform and Linux having a default encoding of UTF8. There is a lot more information here on the proposal for PowerShell Core and encoding going forward.

So, let’s change the encoding of the manifest file to UTF8:

Now let’s change the manifest file again and see if we can view the changes in Git:



Or in VS Code:

Happy Days 🙂

Thanks to Joey Aiello for sharing this on today’s community call.


Can’t Clone Git Respository in SourceTree: Failed to connect….No error

While attempting to clone a Git based repository in Stash via the SourceTree client, I received the following error:

fatal: unable to access ‘http://[email protected]:443/repo.git/’: Failed connect to company.local:443; No error

No error obviously doesn’t give many clues, however this post suggested something to do with proxy settings.

My web browsers were configured to use an internal web proxy via an automatic configuration script and I could successfully navigate to the repository via a web browser. My SourceTree client appeared to be configured correctly since it was set to use the same proxy settings:


The aforementioned post suggested that it was actually the Git command line tools which also need to be configured to use a proxy and the handy checkbox Add proxy server configuration to Git / Mercurial does that for you.


I configured that setting and lo and behold could then clone the repository.


Using Git, Stash and Dropbox to Manage Your Own Code

Sometimes I’m asked how I manage my own (PowerShell) code, in terms of version control, backups, portability etc. In this presentation I demonstrated how my PowerShell code is typically broken down into functions and then placed into modules. This allows me to make very generic code for granular tasks, typically either to plug a gap missing from the out-of-the-box cmdlets or maybe stringing a few of them together. As a consultant this enables me to build up a toolkit of functions for particular scenarios gained over various different experiences and use them in a modular fashion where needed for each particular project. However, once these number in the hundreds how do you manage them effectively? I need them to:

  • be easily available depending on where I am working
  • be backed up
  • track changes via version control, useful even if you are not working in a team developing code together – mostly so I can remember how or why I changed something 🙂

So I’m going to run your through the system I have found that works for me. It uses the following components:

  • A Dropbox account to sync the code between different machines, be available to download via a web browser and also store the code outside of my home lab. This means I can get access to my functions pretty much wherever I am and whether I am using my own or a customer machine.
  • A Linux VM in my homelab to run Git and Atlassian Stash for version control – $10 for a 10 user license (free to try out for 30 days)
  • Atlassian SourceTree. Free Git client for Mac or Windows

DropboxCode Stash I discovered Stash via a previous customer and found it to be a very useful and easy to use add-on to manage Git repositories. It’s possibly overkill for my current needs, but I have worked on shared code projects in the past and it could be useful to have an easy way to do this in the future. If you are thinking “why not use GitHub?”, there are reasons for this. While I share a lot of my code via this blog and possibly via GitHub in the future, there are some commercial and other reasons why I’m not able to share everything. GitHub has private repositories for this, but they start at $7 a month, so this approach with a home hosted Stash does me fine for now. Setting Up Stash I have a 1 vCPU, 1GB Ubuntu VM, installed with the Minimal Server option. The first thing to do is install Git. The below command will install Git and any dependencies.

sudo apt-get install git-core

Stash01 Check the versions  of Git and Perl. The version of Git should be 1.7.6 or higher. The version of Perl should be 5.8.8 or higher. (Note that out of the box RedHat / Centos currently do not include a version of Git that supports Stash.)

git --version
perl --version

Stash03 Check the version of Java and install if necessary. The version of Java should be 1.6.0 or higher. The below is the easiest way I found to do this.

java -version
sudo apt-get purge openjdk*
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
java -version

Stash04 Create an install folder, download the Stash installation files (obviously change the version number for that which you wish to download) and extract the download.

sudo mkdir /var/stash
sudo mkdir /var/stash/install
sudo mkdir /var/stash/home
cd /var/stash/install
sudo wget http://www.atlassian.com/software/stash/downloads/binary/atlassian-stash-2.11.4.tar.gz
sudo tar zxf atlassian-stash-2.11.4.tar.gz

Create a user account to run Stash under.

sudo /usr/sbin/useradd --create-home --home-dir /usr/local/stash --shell /bin/bash stash

Set STASH_HOME in setenv.sh to /var/stash/home.

sudo vi atlassian-stash-2.11.4/bin/setenv.sh

Stash05 Change the ownership of the stash folder and below to the stash account

sudo chown -R stash /var/stash

Start Stash.


Stash06 Navigate to the Setup Wizard at http://hostname:7990 Take the option for an Internal database Stash07 Enter your license key Stash08 Enter Administrator credentials and Go to Stash (I am not using the accompanying Jira product) Stash09 This will take you to the login page where you can authenticate with the credentials you just created. Stash10 You should now see the Stash Welcome Page. Stash11 Connecting the SourceTree Client to Stash Download the SourceTree Client for Mac or Windows and get it installed. Once installed, fire up the client. You may be prompted to install Git for your local client to issue Git commands, go with the embedded version if so: Stash12 Say No to Mercurial (unless you wish to use that as well) Stash13 Enter your information – if you have a GitHub account and wish to use repositories there it can be useful to add the associated email account here. Stash14 Accept the recommendation to use Putty Stash15 If you want to use an SSH key then enter that here, I’m not going to for this tutorial. Stash16 Enter your credentials for the Stash website (and others if you wish to) Stash17 Once complete, the SourceTree client will open. They are pretty regular at providing updates for it, so you may be prompted to install further updates before first use. Stash18 Stash19 Stash20 Now we need to create a project and a repository. First of all through the web interface to Stash create a relevant project. (I liked the way it shortened this one to POW – reminds me of the old Batman series) Stash20a Stash20b Now create a repository Stash20c Stash20d Further down this page you will find instructions on how to upload existing code, which in my case is what I want to do. Stash26a From the SourceTree client open up a Git terminal and run the above commands: Stash26 Stash27 Stash28 At this point if you navigate back to your Stash website you should see your files have been uploaded. You can view inside the code too via the webbrowser. Stash31 Now I need to configure the SourceTree client to be aware of this repository. Click the button for Clone / New and choose Add Working Copy. Enter the path to your working folder and Add. Stash29 It is now available in the SourceTree client. Stash30   So now when I either:

  • Edit code directly on my laptop
  • Or copy code edited elsewhere and pop it in the Dropbox folder

Following synchronisation with the Dropbox folder, the SourceTree client will show that files have changed and require committing. In the below example a couple of minor spelling mistakes have been corrected. SourceTree shows the file has been updated and also what has been changed since the previous version. Red line was removed, Green line was added. Stash32 Right-click the file and choose Commit. Stash33   Enter an explanation for what was changed in this version and it also makes sense to select Push commits immediately to origin so that you create the commit and also submit it in the same action. Stash34 Assuming there were no errors then SourceTree should display no files to commit and navigating to the Log / History tab you will notice that a history of your changes will start to build up. Again, useful if you need to track back and see what changed and when. Stash35