Given a repo
from GitPython, how can I create a new local branch, add some files, and push it to remote using GitPython?
To create a repo
:
from git import *
curr_dir = os.path.dirname(os.path.realpath(__file__))
repo = Repo(curr_dir)
For now, I'm just using 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)])