2

I want to create a folder hierarchy in a GIT repository on Azure Devops using the REST API. (automated via a script)

The docs https://learn.microsoft.com/en-us/rest/api/azure/devops/git/pushes/create?view=azure-devops-rest-6.1 provide only examples how you can create files, but not folders.

Does anyone know how to do that?

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
Richard Bayer
  • 23
  • 1
  • 3
  • I hope this might help you with your topic. https://stackoverflow.com/questions/12258399/how-do-i-create-a-folder-in-a-github-repository – Philipp May 12 '22 at 13:35

2 Answers2

2

You can't. Git tracks files in a tree structure. If there is no file (leaf), there is no folder (tree-branch).

So you'll need to add at least one file to the empty folder.

Hence the way to create a folder with the REST API, is to create a file with a new folder as its root.

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
1

This thread might help you out with your problem:

How do I create a folder in a GitHub repository?

Basicly use / in the file name field to create folder(s), e.g. typing folder1/file1 in the file name field will create a folder folder1 and a file file1.

Philipp
  • 11
  • 1
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/31757739) – Kuro Neko May 17 '22 at 03:47
  • @KuroNeko i posted the Link - then a summary with the fix – Philipp Jun 10 '22 at 08:55