Semi-coherant ramblings about cool tech stuff

View project on GitHub
By Tristan Rhodes Posted 16 November 2015

Fun with Git automation

Fun with Git automation


Git is a fantastic lightweight source control system. We love it here. We love it so much that we try and automate common tasks in it with powershell because all developers are lazy.

This post is about the many hours spent trying to diagnose credential issues, and how to not repeat it. :)

Git credentials

We are using git through Visual Studio Online, the web based project management tool by Microsoft. It comes with lots of nice API’s, and some of them do the same thing, in different ways, using different credentials, which gets a bit confusing.

We are this with a companies federated login provider so our credentials are either our e-mail address, or depending on the API / approach being used in the automation.


To connect to a git repostory using a git client and embedded credentials in the URL, you need a uri that looks like this:


This works pretty well, it’s easy enough to use this approach to connect to github. However, when using a federated login provider and you have and special charachters in your password, then the URL will fail when it looks like this:


The error messages are not helpful, but the root causes were as follows:

So when using powershell, create a vso access token (My Profile -> Security), then using the username and your access token as the password, use the powershell with your :

$rawUrl = 'https://{0}:{1}';
$gitUrl = $rawUrl -f [System.Net.WebUtility]::UrlEncode($username), [System.Net.WebUtility]::UrlEncode($password)

Then use the git URL when performing pulls, push and clone operations.

Tristan Rhodes
Tristan Rhodes