Git with Python
There are some Python packages that we can use with Git and GitHub. In this section, we will take a look at the GitPython and PyGithub libraries.Â
GitPython
We can use the GitPython package, https://gitpython.readthedocs.io/en/stable/index.html, to work with our Git repository. We will install the package and use the Python shell to construct a Repo
object. From there, we can list all the commits in the repository:Â
$ sudo pip3 install gitpython $ python3 >>> from git import Repo >>> repo = Repo('/home/echou/Master_Python_Networking/Chapter10/TestRepo') >>> for commits in list(repo.iter_commits('master')): ... print(commits) ... 0aa362a47782e7714ca946ba852f395083116ce5 a001b816bb75c63237cbc93067dffcc573c05aa2 bc078a97e41d1614c1ba1f81f72acbcd95c0728c 2ec5f7d1a734b2cc74343ce45075917b79cc7293 c98373069f27d8b98d1ddacffe51b8fa7a30cf28 a3dd3ea8e6eb15b57d1f390ce0d2c3a03f07a038 5f579ab1e9a3fae13aa7f1b8092055213157524d
We can also look at the index entries...