Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub API - write to repo

Tags:

git

github

api

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

like image 338
Ricardo Augusto Avatar asked Jul 12 '11 17:07

Ricardo Augusto


1 Answers

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

like image 133
TheIceBear Avatar answered Oct 04 '22 23:10

TheIceBear