Few days ago we talk about
1- Initiate git object in python by providing path:
2- If you want to
3- Let's say you want to set username and email for git author:
4- Now to add a specific file to staged:
5- Commit the staged file with a message:
6- The final step is to push to a remote repo:
#python #git #gitPython #pull #push #author
gitPython
to work with git inside of python. The code below is a sample that would do all routine tasks like pulling and pushing or commit.1- Initiate git object in python by providing path:
from git import Repo
repo = Repo(repo_path)
2- If you want to
pull
results from git repo:repo.git.pull('origin', 'refs/heads/dev')
3- Let's say you want to set username and email for git author:
config = repo.config_writer()
config.set_value("user", "email", author_email)
config.set_value("user", "name", author_name)
4- Now to add a specific file to staged:
index = repo.index
index.add([file_path])
5- Commit the staged file with a message:
index.commit(commit_message)
6- The final step is to push to a remote repo:
repo.git.push('origin', 'refs/heads/dev')
#python #git #gitPython #pull #push #author