如何使用GitPython从给定的repo
创建新的本地分支、添加一些文件并将其推送到远程?
要创建一个repo
:
from git import *
curr_dir = os.path.dirname(os.path.realpath(__file__))
repo = Repo(curr_dir)
目前,我只是使用subprocess
:
def publish_changes_to_git(commit_msg):
curr_time = time.time()
ts = datetime.datetime.fromtimestamp(curr_time).strftime('%Y-%m-%d-%H-%M-%S')
branch_name = "auto-commit-{ts}".format(ts=ts)
subprocess.check_output(["git", "checkout", "-b", branch_name])
subprocess.check_output(["git", "add", SOME_PATH])
subprocess.check_output(
["git", "commit", "-m", "auto-git-commit: {msg}".format(msg=commit_msg)])