2

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.

Dinko Pehar
  • 4,475
  • 3
  • 20
  • 42
Saurav Saha
  • 551
  • 6
  • 25

1 Answers1

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