How to execute git command in a identified path?
Question: I want to execute git command in python program. I have tried os.system("git-
command") As we know, git command can be executed correctly only in the
directories which contains repositories. I have tried to print current path
and this path is not what I hope for, it does not contains repositories. Now
my question is how to execute git command in a identified path.


Answer: Use the [`subprocess`
module](http://docs.python.org/2/library/subprocess.html); pick one of the
functions that suits your needs (based on what output you need). The functions
all take a `cwd` argument that lets you specify the directory to operate in:

    
    
    import subprocess
    
    output = subprocess.check_output(['git', 'status'], cwd='/path/to/git/workingdir')
    

