Just as we can create new files in a Github repo using PyGithub
, can we create directories/folders in a Github repo using PyGithub? I have been searching through the PyGithub docs but I haven't found anything substantial.
Asked
Active
Viewed 1,430 times
3

Dinko Pehar
- 5,454
- 4
- 23
- 57

Saurav Saha
- 745
- 1
- 11
- 30
-
https://stackoverflow.com/q/12258399/2614364 – Bertrand Martel Mar 23 '20 at 19:07
1 Answers
4
You can create directory using the same method as for when creating a file. But the catch is to create a file inside directory since Git tracks only folders which have files inside 1.
>>> repo = g.get_repo("PyGithub/PyGithub")
>>> repo.create_file("example/test.txt", "test message", "content_of_file", branch="test")
{'content': ContentFile(path="example/test.txt"), 'commit': Commit(sha="5b584cf6d32d960bb7bee8ce94f161d939aec377")}

Dinko Pehar
- 5,454
- 4
- 23
- 57