15

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 Answer 1

22

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot. Could you tell me if it is possible to rename git repo using API?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.