Reputation:
Is there any way to create a new folder in git repository using their API? Is it possible to do this with Trees API?
Upvotes: 15
Views: 5215
Reputation: 3331
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
Upvotes: 22