CHunky Universe of Vigourous Astonishing SHarepoint :)

Tag Archives: git

Git Merge develop to main in an Azure DevOps Release

This post is a techy one. It’s about running git commands in Azure DevOps Releases in order to finalize a deployment job to production.

Let me first describe our scenario:

We use Azure DevOps for code and for deployment. Our branch strategy a simplified Gitflow model, where all the current work is merged to the “develop” branch. The code from the “develop” branch is then built and released to staging environments and production. After a release to Production and regression tests the develop branch needs to be merged into the “main” branch (or “master”). So simply put, the git merge into main is what we mean by finalizing a production release.

The “Finalize” stage in a release definition consists of one step: a bash script. But before you can run git commands you need to configure a couple things. Let’s go through them:

Step 1: Permissions

Step 2. New Stage

Next, create a new stage, call it “Finalize Production Deployment” (or other name of your choice). On the Build Agent step, enable “Allow scripts to access the OAuth token”

Add a step: Bash, call it “Git – merge changes to main”. Paste this git code.

git config –global ""
git config –global "Azure DevOps"
EXTRAHEADER="Authorization: Bearer $(System.AccessToken)"
git -c http.extraheader="$EXTRAHEADER" clone $REPO
cd $(Build.Repository.Name)
MAINBRANCHNAME=$(git rev-parse –abbrev-ref HEAD)
git config http.$REPO.extraHeader "$EXTRAHEADER"
echo — Merge $(Build.SourceBranchName) to $MAINBRANCHNAME
git fetch origin $(Build.SourceBranchName) –prune
git merge origin/$(Build.SourceBranchName) -m "merge $(Build.SourceBranchName) to $MAINBRANCHNAME" –no-ff
echo — Create tag named $TAGNAME
git tag -a -m "$(Build.SourceBranchName) installed to production" $TAGNAME
git push origin $MAINBRANCHNAME
git push origin –tags

That’s it, the code is pretty universal. Let me know if something does not work.

You can stop reading unless you want more details 🙂

More details

A neat list of all available variables

When I started working I found this very useful: The built-in “Initialize job”. Click on that:

There you can find all the built-in and your variables in a nice list. Pretty useful for building a bash script:

Here is how I construct the repo url, neat, isn’t it?

Pipelines vs. Releases

If you run this code in a classic Release Definition, you won’t get the repo. You need to clone it first. Why Release and a Pipeline. Well, due to reasoning described in my other blog post, we still run Releases: Azure Key Vault vs. Pipeline Variables. But Pipelines should work, too.


I found it useful while mickle-mackling with the finalize step, disable all the other steps and commenting out the actual push to origin. That way I could run it fast and focus on the steps I needed to fix first.


Before you can configure the authorization header, you need to clone it first and cd into that directory. In order to clone it you need to have the extraheader. Tough luck? No, not at all, you just need to add in two places, when cloning and and then in the git repository for all the following commands:

User Identity

Using git config you can define any user identity. Use something that makes sense and is easy to recognize.

main vs. master

If your repos main branches are both main and master, no worries, you don’t need to guess or create a variable. All you need to do is to check the current branch after you have cloned it. NB: it’s different in case you use a Pipeline.

Further reading and links

Re-discovering Github

Github has changed a lot. While working mostly in Azure DevOps I haven’t followed all the development on Github. Now when I look at that, I am really amazed.

Private Repos for Free accounts

Well, for me it is not as interesting, because with my free account, I don’t see any harm having my labs public. But I know, some people used bitbucket for their smaller private repos.

Github Project

I suppose it is the Azure DevOps Project concept that was copied to Github, a place for planning and having multiple connected repos.

Github CLI

For me the Github CLI is the best news. Being able, from command line, not only to git stuff, but also see and create issues, manage pull requests, repos, releases. That means more automation. I like it.

Also being able to work with gists is nice.

main instead of master

That’s brand new. The word “master” is offensive to some people. (sources: Github, statement, zdnet).

So my test repo is one of the first ones that gets “main” as its main branch. Well, that’s not wrong at all. It connects it back to the olden days of TFS, too 🙂

Load git into PowerShell

Just a little productivity tip. If you use git on Windows, you probably already have the Github for Windows application. This application adds the Git Shell:


The Git Shell will open a PowerShell window and execute shell.ps1 from the Github directory:


What it won’t do is to load your personal PowerShell profile. I want to use my PowerShell profile that creates some links and adjust the look-and-feel and the promt of the shell. By the way I have published my profile.ps1 as a gist:

I also want to have git in PowerShell available directly. The answer is in the shell.ps1 in the Github folder:


So add this line to your profile.ps1 as I did:

. (Resolve-Path "$env:LOCALAPPDATA\GitHub\shell.ps1")

That’s it. If you haven’t seen the “DOT” in PowerShell scripts, it is called dot sourcing, it will execute the script and keep all the variables and references within the script.

An alternative

If you do not have Github for Windows, there is another way to load git functionality into PowerShell:

.tfignore – “.gitignore” for TFS

I haven’t used TFS so much. But I like it so far. It works smoothly, both TFS 2012 (on premises) and TFS Preview (online). I really appreciate that Microsoft has been inspired from git – the world’s best VCS :). For example .tfignore which works exactly like the .gitignore file. It is nice that the non-classic Microsoft dot notation convention for naming the hidden files is chosen.  So if you have any files to ignore just do it like you did in your git projects. Here is a .tfignore which I use in my SharePoint project for now. I suppose it will be extended soon:

# Ignore Reshaprer files
# Ignore published wsp outputs

Put .tfignore file in the root of your TFS Project. You can of course, let VS2012 create it automatically in the VS2012

.gitignore for .net

At appharbor there is a simple .gitignore file for .net applications. If you use Resharper, you may find the extended version of .gitignore useful. A most comprehensive .gitignore can be found on gitextensions website. (Thanks to Vasiliy Aksyonov for the comment):

#ignore thumbnails created by windows
#Ignore files build by Visual Studio

If git tracks some files you don’t want it to track, just remove these files from the git repo:

git rm --cached file

Next: “.gitignore” for TFS: .tfignore

Team Explorer


Until now I have only worked with svn and git. So I am very curious about the Team Foundation Server and Team Explorer which all talk much about. The best thing is the integration with the issue tracking. I can see all work item, or just my work items.

Another fine feature, at leat if you use codeplex, is the Team Explorer Everywhere.

The Team Explorer Everywhere client works on Windows, Linux, Mac, or Solaris. It provides a command line client and plug-in for Eclipse to access Team Foundation Server. For information on obtaining the client and connecting to the Team Foundation Server please read the Team Explorer Everywhere Client wiki page. You will need the information on the right to connect to the Team Foundation Server in Team Explorer Everywhere.

.gitignore for android

.gitignore is very important. This file tells git which files not to care about. I found a good template for android .gitignore:


The only thing I have added is the last row: .classpath.

Good beginners’ tutorial on android, eclipse and git

Smashing magazine has a pretty good tutorial how to start programming for android using git, github, eclipse and datastorage. I recommend:

Get Started Developing For Android With Eclipse, Reloaded

Set up the Lusites development environment

There is a very good wiki page which describes how to set up the environment. If you think something is missing there, just leave a comment here. Much of that was inspired by a useful tutorial from

Update from git

So if you have an existing copy of the project, just type:

git pull origin master

Or in Egit in Eclipse, right-click on repo and run “Fetch from upstream”.

Daniel Chronlund Cloud Tech Blog

News, tips and thoughts for Microsoft cloud fans

Вула Чăвашла

VulaCV - Чăвашла вулаттаракан сайт

Discovering SharePoint

And going crazy doing it

Bram de Jager - Architect, Speaker, Author

Microsoft 365, SharePoint and Azure

SharePoint Dragons

Nikander & Margriet on SharePoint

Mai Omar Desouki

PFE @ Microsoft

Cameron Dwyer

Office 365, SharePoint, Azure, OnePlace Solutions & Life's Other Little Wonders


Me and My doings!

Share SharePoint Points !

By Mohit Vashishtha

Jimmy Janlén "Den Scrummande Konsulten"

Erfarenheter, synpunkter och raljerande om Scrum från Jimmy Janlén

Aryan Nava

DevOps, Cloud and Blockchain Consultant


SharePoint for everyone


Ryan Dennis is a SharePoint Solution Architect with a passion for SharePoint and PowerShell

SharePoint 2020

The Vision for a Future of Clarity

Aharoni in Unicode

Treacle tarts for great justice

... And All That JS

JavaScript, Web Apps and SharePoint


Mostly what I know and share about...