Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a file to a Git repository using GitHub API?

It is possible to add (commit) a new file to a Git repository in a browser according to GitHub documentation.

I want to do the same in my Java application.

Where can I find GitHub API documentation for the API call that is being used here?

Here are the request data I found using Firefox:

Screenshot

Screenshot

like image 710
Dmitrii Pisarenko Avatar asked Sep 13 '25 17:09

Dmitrii Pisarenko


2 Answers

For creating or updating file contents in a GitHub repo, you can use the below GitHub v3 API

PUT /repos/{owner}/{repo}/contents/{path}

The documentation of the above API can be found here.

like image 168
Madhu Bhat Avatar answered Sep 16 '25 10:09

Madhu Bhat


curl -X PUT -H "Authorization: Bearer <access_token>" -H "Content-Type: application/json" -d '{"message":"Commit message","content":"<file_content>","branch":"<branch_name>"}' https://api.github.com/repos/{owner}/{repo}/contents/{path}
like image 33
Erçin Dedeoğlu Avatar answered Sep 16 '25 11:09

Erçin Dedeoğlu