Meet the specified naming conventions in Azure DevOps Git

Collaborating in a Azure DevOps Git repository with a lot of people could become a chaos regarding branch folders. At the start of a project you can specify naming conventions for the branch names. In these names you can incorporate a ‘/’ and the tooling (Azure Devops, TFS and Visual Studio) will see this as a folder. Example for the naming conventions:

  • One root branch in the repository for example “master”.
  • Create new branches under “/features/[feature name]”

With naming conventions specified you should be able to enforce these rules as well. In Azure DevOps repositories you have this options by setting permissions on branch levels. Using this option also allows you to configure specific names for specific groups of users.

Prerequisites

  • Team Foundation version control command (tf.exe). This tooling is normally installed when using the Visual Studio Developer Command Prompt.
  • An existing Azure DevOps account.
Developer Command prompt

Steps

The most important thing to do first is to remove the creation of branches on the root level of the repository.

tf git permission /deny:CreateBranch /group:Contributors /collection:[Azure DevOps Instance] /teamproject:[ProjectName] /repository:[Repository Name]

The script above removes the permissions for the “Contributors” group within the Azure DevOps project. When the default permissions are removed specific permissions for folders can be added to the repository.

tf git permission /allow:CreateBranch /group:Contributors /collection:[Azure DevOps Instance] /teamproject:[Project Name] /repository:[Repository name] /branch:features

The “branch” arguments specifies the folder name you allow within the repository. In the example permissions are added to create branches in the features folder for users in the “Contributors” group.

Git branch permissions

Leave a Reply

Your email address will not be published. Required fields are marked *

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