Ótima lib Python para lidar com repositórios git.

https://gitpython.readthedocs.io/en/stable/index.html

Instalação da lib

pip install GitPython

Uso

from git import Repo
 
# New repo
repo = Repo.init(path_to_dir)
 
# existing repo
repo = Repo(path_to_dir)
 
# Last commits
tree = repo.head.commit.tree
 
# We must make a change to a file so that we can add the update to git
 
update_file = "dir1/file2.txt"  # we'll use local_dir/dir1/file2.txt
with open(f"{local_dir}/{update_file}", "a") as f:
    f.write("\nUpdate version 2")
 
# $ git add <file>
add_file = [update_file]  # relative path from git root
repo.index.add(add_file)  # notice the add function requires a list of paths
 
# $ git commit -m <message>
repo.index.commit("Update to file2")
 
# Push to origin
origin = repo.remote(name='origin')
origin.push()