I am asking this to know about the github API and it's usage towards the actions that we do like checking out the code, committing files/changes into the code etc.,
Asked
Active
Viewed 790 times
1 Answers
0
While it would be much easier to use an existing solution (such as a library) it is somewhat possible to do this using the REST API. As this question includes multiple steps, let's break them down.
1. Clone a Repository
As explained in this answer, there is no way to directly clone using the GitHub REST API, however you can use the REST API to either download the repository or fetch the clone url and manually clone.
2. Make a Commit and Push to the Remote
This is possible, though it is much more complex than using an existing library. The Git Database portion of the API defines a set of steps to commiting a change to a file which can be used as a starting point to make general commits.
- Get the current commit object
- Retrieve the tree it points to
- Retrieve the content of the blob object that tree has for that particular file path
- Change the content somehow and post a new blob object with that new content, getting a blob SHA back
- Post a new tree object with that file path pointer replaced with your new blob SHA getting a tree SHA back
- Create a new commit object with the current commit SHA as the parent and the new tree SHA, getting a commit SHA back
- Update the reference of your branch to point to the new commit SHA
This answer shows an implementation in Python, but has helpfully included the requests every step of the way.

The Otterlord
- 1,680
- 10
- 20
-
,thanks for the instructions but It would be better to have practical understanding through postman API testing. Please do share me some data on where I could Check for that.I am good with the Clone API but in need of more understanding on Commit – Subramanian Natarajan Sep 14 '21 at 13:29
-
The [answer](https://stackoverflow.com/a/63461333/14104186) I linked has all the requests in order. I can add them along with explainations to my answer if you wish, but I've not used postman before, and have no idea what postman api testing is or how it would help. Is there a specific part you a struggling with? – The Otterlord Sep 14 '21 at 14:05