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 747 times
2
Dinko Pehar
- 4,475
- 3
- 20
- 42
Saurav Saha
- 551
- 6
- 25
-
https://stackoverflow.com/q/12258399/2614364 – Bertrand Martel Mar 23 '20 at 19:07
1 Answers
2
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
- 4,475
- 3
- 20
- 42