I'm attempting to use Azure DevOps Services Rest API to create a new branch from master but I've been unsuccessful.
Docs: https://learn.microsoft.com/en-us/rest/api/azure/devops/git/refs/update-refs?view=azure-devops-rest-5.1#examples
Endpoint: https://dev.azure.com/{{organization}}/{{project}}/_apis/git/repositories/{{repositoryId}}/refs?api-version={{api-version}}
Body:
[
{
"name": "refs/heads/new-test-branch-from-api-call",
"oldObjectId": "{{masterObjectId}}",
"newObjectId": "{{newObjectId}}"
}
]
Results:
{
"$id": "1",
"innerException": null,
"message": "TF401035: The object '****************************************' does not exist.",
"typeName": "Microsoft.TeamFoundation.Git.Server.GitObjectDoesNotExistException, Microsoft.TeamFoundation.Git.Server",
"typeKey": "GitObjectDoesNotExistException",
"errorCode": 0,
"eventId": 3000
}
A comment on this post states that this is the route to take. Also states that the repositoryId
should be used and the newObjectId
which results in:
{
"$id": "1",
"innerException": null,
"message": "An object ID must be 40 characters long and only have hex digits. Passed in object ID: ********-****-****-****-************.",
"typeName": "System.ArgumentException, mscorlib",
"typeKey": "ArgumentException",
"errorCode": 0,
"eventId": 0
}
newObjectId
is the object id of the existing branch. Really not sure why this is named new when it is actually older. Very odd.
[
{
"name": "refs/heads/new-test-branch-from-api-call",
"newObjectId": "{{BranchObjectIdGoesHere}}",
"oldObjectId": "0000000000000000000000000000000000000000"
}
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With