How to allow commits only for specific names/emails in Azure DevOps?

Viewed 1461
2 Answers

Due to the distributed nature of Git, it's not uncommon for a user to pull in changes made by another person and then push these into their own git repository. This is essentially what a Pull Request does.

Because of this, neither Git, not Azure DevOps Repos knows whether you are pushing commits with different names and email addresses intentionally or not.

It's also why Azure DevOps Reps tracks the "Pusher" as well as the "Committer". If you look at the Pushes in your repository, you'll see that each time new commits were pushed to the repository, Azure DevOps Repos has kept track of who performed the push and which commits were contained in it.

If you want to ensure you don't create new commits with the wrong emailaddress/name, then your best bet is to add a local pre-commit-hook. You can find an example here. These hooks will run on your local repository even prior to the commit being pushed.

Another option could be to setup a Policy on the branch you want to go to and as part of that policy run a quick CI build. In there you can check whether there are unwanted names and fail the pull request.

Related