VSTS 扩展:从新的存储库初始化或创建主分支

VSTS Extension: Initialize or create a master branch from a new repo

是否可以使用 Visual Studio Team Services REST API 来初始化新创建的存储库?

不敢相信我在 VSTS REST api 文档中错过了这个,但这里是你如何在 vsts 上创建和初始化一个新的 git 存储库并使用 TFS 2015 本地测试它

创建新存储库:

Post: http://tfs:8080/tfs/DefaultCollection/_apis/git/repositories?api-version=3.0

正文:

{
  "name": "AnotherRepository",
  "project": {
    "id": "e7154789-27db-4ee5-a192-4d69594c6588"
  }
}

正在初始化新存储库:

Post: http://tfs:8080/tfs/DefaultCollection/_apis/git/repositories/4968177d-1f0b-4009-a635-272af892f536/pushes?api-version=3

正文:

{
  "refUpdates": [
    {
      "name": "refs/heads/master",
      "oldObjectId": "0000000000000000000000000000000000000000"
    }
  ],
  "commits": [
    {
      "comment": "Initial commit.",
      "changes": [
        {
          "changeType": "add",
          "item": {
            "path": "/readme.md"
          },
          "newContent": {
            "content": "My first file!",
            "contentType": "rawtext"
          }
        }
      ]
    }
  ]
}

VSTS REST 文档: