Saar Buchnik
Saar Buchnik

Reputation: 126

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

I recently moved to the Azure-devops git from Github. I found that sometimes my commits have name & email different from the ones I signed in with.

I figured that this is because of my local git configurations, and was able to fix it.

I was wondering if there is a way to prevent it from happening. i.e - approve the commit only if the email and username are the same as the email and username used to sign in.

Upvotes: 3

Views: 2945

Answers (2)

Nik
Nik

Reputation: 2726

You can do this via a policy these days, for email anyway.

Go to the repo, settings, "Commit author email validation". You can specify wildcards.

https://mattvsts.github.io/2019/11/13/did-you-know-branch-policies/

Upvotes: 3

jessehouwing
jessehouwing

Reputation: 114822

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.

Upvotes: 1

Related Questions