Warm tip: This article is reproduced from serverfault.com, please click

Is there a way to query all branches associated with a GIT repository using AZ CLI extensions?

发布于 2020-12-14 17:06:29

I am trying to code up a condition to check if a git repo has a specific branch. If not, then create that branch.

I know the following commands via command line can be used to achieve this:

git branch
git checkout etc..

But I was wondering if there are any Azure Command line extensions to do this?

Questioner
user9900698
Viewed
0
Shamrai Aleksander 2020-12-15 02:03:33

You can try az repos ref list. Use the filter option to search branches like "heads/your_path" (example on rest API documentation)

Example:

az devops login --org "https://dev.azure.com/<your_org>"
Token:

az repos ref list --org "https://dev.azure.com/your_org" -p TeamProject -r RepoName --filter heads/

[
  {
    "creator": {
      "descriptor": "------",
      "directoryAlias": null,
      "displayName": "------",
      "id": "0f98bf70-30c3----",
      "imageUrl": "----",
      "inactive": null,
      "isAadIdentity": null,
      "isContainer": null,
      "isDeletedInOrigin": null,
      "profileUrl": null,
      "uniqueName": "-------",
      "url": "-------"
    },
    "isLocked": null,
    "isLockedBy": null,
    "name": "refs/heads/dev",
    "objectId": "4734085d73703e88ae39-----",
    "peeledObjectId": null,
    "statuses": null,
    "url": "-----"
  },