7

I looked all documentation, but it doesn't answer my question.

There is a way to write to a repo (upload a file)? Something like create a folder, and upload a readme.md

desertnaut
  • 57,590
  • 26
  • 140
  • 166
Ricardo Augusto
  • 548
  • 1
  • 8
  • 18
  • 1
    Pushing using the github api seems quite more complex, then just `git push`. You should read http://developer.github.com/v3/git/ . I suggest you to use `git push` instead, because manipulating the raw `git`-data requires, that you understand gits internals. – KingCrunch Jul 12 '11 at 17:25

1 Answers1

1

Folders do not need to be created as they only exists implicitly in git. Meaning that if you have a file with path folder/file.txt then your git client knows to create a folder called "folder" where the file "file.txt" is saved, but to git it is just a file with the name "folder/file.txt"

You can use: PUT /repos/{owner}/{repo}/contents/{path} where {path} is the folder path and file name, and put message and file content (Base64 encoded) in the body.

When you are updating a file you also need to indicate which version in the git history of the file you want to update. Read more here https://docs.github.com/en/rest/reference/repos#create-or-update-file-contents

TheIceBear
  • 2,912
  • 9
  • 23