Call git via subprocess . From one of my own programs:
def gitcmd(cmds, output=False): """Run the specified git command. Arguments: cmds -- command string or list of strings of command and arguments output -- wether the output should be captured and returned, or just the return value """ if isinstance(cmds, str): if ' ' in cmds: raise ValueError('No spaces in single command allowed.') cmds = [cmds]
Some examples:
rv = gitcmd(['gc', '--auto', '--quiet',]) outp = gitcmd('status', True)
source share