Create folder using GitHub API

隐身守侯 提交于 2020-04-10 07:13:07

问题


Is there any way to create a new folder in git repository using their API? Is it possible to do this with Trees API?


回答1:


Yes, but you'd need to create a file in the directory because git only tracks directories with files in them.

Example:

Say we have a user called "foo" who has a repo called "bar". The repo has the following contents:

├── LICENSE
├── main.go
├── main_test.go
└── README.md

If we want to create a file in the examples directory called example.go, we would issue the following request:

PUT /repos/foo/bar/contents/examples/example.go

The template for the request to create new files is as follows:

PUT /repos/:owner/:repo/contents/:path

See http://developer.github.com/v3/repos/contents/#create-a-file



来源:https://stackoverflow.com/questions/20045572/create-folder-using-github-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!