0

Ok, this seems like a stupid question and I don't have a lot of experience using git as I have always been dependent on GitHub desktop for my work. So my question is, Can a github remote repo be committed to and pushed to via only the github api. Can it be done without installing git on your system? I have used PyGitHub and git-python or even python subprocess that can be used to create a remote repo, initialize and add to the the local repo and perform the commit and pushes to the remote repo and I know that these services require the use of the git client installed on the system.

So I was just wondering if only the standalone github api can be called through python requests to do the same but the requirement being that I don't have to get Git installed in my local system. Any help on the matter would be really enlightening.

phd
  • 82,685
  • 13
  • 120
  • 165
Saurav Saha
  • 745
  • 1
  • 11
  • 30

2 Answers2

1

Can a github remote repo be committed to and pushed to via only the github api. Can it be done without installing git on your system?

Kinda: you can interact with the raw objects via the API, I'm not sure you can behave as if git was on your machine and to push/pull from a local working copy as you'd do if you did have git installed locally.

My experience of it is that it requires some understanding of the low-level fundamentals of Git (blobs, trees, commits, refs, and their relations): the v3 API exposes a git data / git database endpoint which provides transparent access to low-level git structures. There are some limitations (e.g. can't interact with a brand new empty repository via this, you have to have at least one commit in it somehow, high-level operations like "cherrypick" or "rebase" are unavailable and have to be hand-rolled if you want them, ...) but aside from that it works fine.

To understand the low-level objects I would recommend the "Git Internals" chapter of the git book, sections 10.2 Git Objects and 10.3 Git References. There are also "from the ground up" tutorials out there which explain these structures in a more hands-on way by building partial git clients from the ground up.

So I was just wondering if only the standalone github api can be called through python requests to do the same but the requirement being that I don't have to get Git installed in my local system.

See above, kinda: you can most certainly interact with a github repository via the API in most every way possible, but rebuilding a git client out of the API might be difficult.

Masklinn
  • 34,759
  • 3
  • 38
  • 57
  • Ok! Could you please point me out some good tutorials if some exist which explain the process a bit better. That would really be helpful! – Saurav Saha Jan 30 '20 at 05:20
  • 1
    @SauravSaha I've not used an any guide or tutorial besides the official doc so I don't know if there are other or better resources, sorry. Maybe ask on the official github forums (https://github.community/t5/GitHub-API-Development-and/bd-p/api)? I can't say it's been the most useful resource ever for me but you might have better luck. – Masklinn Jan 30 '20 at 06:57
  • Ok, I'll look into anyway! Thanks @Masklinn – Saurav Saha Jan 30 '20 at 07:03
0

PyGithub will enable you to deal with whatever we have in Github.com. To manage your local git. Like, committing or pushing or stashing. You might need to use some python modules that deal with Git, not Github. One of the examples could be https://github.com/gitpython-developers/GitPython

karn
  • 80
  • 1
  • 10
  • Both the packages that you mentioned require the installation of Git on your system and that is what I don't require. I clearly stated that I need to directly interact with the API standalone – Saurav Saha Jan 30 '20 at 05:19