from git import Repo from datetime import datetime repo = Repo("./") if not repo.bare: now = datetime.now().strftime("[%H:%M:%S] ") branch = repo.active_branch # Thanks to https://stackoverflow.com/a/65535263/12036073 if list(repo.iter_commits(f'{branch}..{branch}@{{u}}')): print(now + "Remote changes detected, pulling...") repo.remotes.origin.pull() else: print(now + "Up to date") else: print("Repository must not be bare!")