Git Remote Access in Azure Pipelines, possible? I'm trying to achieve the following through the build pipeline.


Default branch: SIT (from the Azure Repos repository)
Trigger: whenever a change is made in DEV branch


In a powershell task do the following:


Merge latest from DEV to the current SIT branch
Deploy the latest from SIT branch
Push the updated SIT branch to the upstream repository


Here is my code:

git checkout -b temp
git merge origin/DEV
git branch -f SIT temp
git checkout SIT
git status
git branch -d temp
git remote add neworigin $(RemoteOrigin)
git push -u origin --all


When I try to push the updated SIT branch using git push -u origin SIT and I'm getting the following error:


  remote: 0000000000aaTF401027: You need the Git 'GenericContribute'
  permission to perform this action. Details: identity
  'Build\d073f6c7-4fa2-4bda-8694-8a41fb808fff', scope 'repository'.
  remote: TF401027: You need the Git 'GenericContribute' permission to
  perform this action. Details: identity
  'Build\d073f6c7-4fa2-4bda-8694-8a41fb808fff', scope 'repository'.
  fatal: unable to access '': The requested URL returned
  error: 403


Can someone help?
I've had a similar issue with git commands in Azure Pipelines.  The reason is that any commands that access the origin server, such as git push need to done by a user that has the credentials to do so.  In your situation, your PowerShell script is running in the user context of Project Collection Build Service (yourProjectName) and it does not have the permissions to contribute to your repo by default.

See this answer, I think it will fix you up: https://stackoverflow.com/a/56542631/11767897