Azure Virtual Directories with Git Deployment

Home / Azure Virtual Directories with Git Deployment

Azure added support for Virtual Directories a while back. It’s easy to add a virtual directory. One issue, though, is deploying to those directories since Azure only supports a single Git (or other) source control repository for the web application.


For instance, here’s my Azure setup with my test site. You can see that I’ve configured multiple virtual directories.

I have set my deployment settings to point to one of my Bitbucket Git repositories. That’s where Azure configuration ends. There are no per-virtual directory deployment settings.

Fortunately, we can create a separate Git repository with Git’s subtree option. With the subtree option, Git allows us to create links to other repositories as sub-directories. Think of this as creating a master repository. The only thing we have to be careful of is that whatever name (prefix) we use for the subtree must match our virtual directory name.

In my case, I created a repository called “azure-merge.” Since I already had my npm Express project, I used that as a starting point.

The first thing that must be done from the azure-merge repository is that the other remote, for the project that I’m going to merge, must be added. I called this “express” to match my virtual directory name (see screenshot).

git remote add express https://someuser@bitbucket.org/someuser/npm-express.git

After the remote is added, we create the subtree. This is where our prefix must match the directory name of our virtual directory. I point the subtree to the master branch of the “npm-express” repository.

git subtree add --prefix=express express master

The last step is to push to our origin remote.

git add -A
git commit -m "Added subtree express"
git push -u origin master

After pushing, the express directory can be seen in our branch.

In the commit view, note that the subtree shows its own commit id, so we know the subtree merge worked.

With that in place, the Azure control panel can be synced to deploy all of our virtual directories. This is a fairly good mechanism for fully utilizing virtual directories and continuous deployment from a Git source without having to jump through too many hoops.

The one caveat (of course there has to be a caveat) is that subtrees will not automatically refresh when the merge repository is updated. This makes sense. Just like any branch from Git, we have to fetch/pull to update our copy of that branch. With that in mind, if I were to update the “npm-express’ repository, in order to get the subtree in my “azure-merge” repository to reflect those changes, I have to update the subtree:

git fetch express
git commit -m "Updated subtree express"
git push -u origin master

One last thing to think also is that the subtree will be pointing to a specific branch. What happens if we want to change the branch? Since the subtree is simply a folder, we can delete it and start over. For example if I were changing from “master” to “release:”

git rm <subtree>
git commit -m "Removing <subtree> master"
git subtree add --prefix=<subtree> <repository> release
git add -A
git commit -m "Adding <subtree> from release branch"
git push -u origin

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.