If you get the following error in your build…
TF401027: You need the Git ‘GenericContribute’ permission to perform
this action. Details: identity
…then, to fix it:
- Copy the guid part of the identity name from the error message
- Go to the repository settings
- Paste the guid into the permissions search box for user or group.
- This will then display a “Project Collection Build Service (OrganisationName)”. Select that user
- Set the permissions as stated in other answers.