Skip to content

Instantly share code, notes, and snippets.

@nathania
Created May 31, 2012 01:33
Show Gist options
  • Save nathania/2840185 to your computer and use it in GitHub Desktop.
Save nathania/2840185 to your computer and use it in GitHub Desktop.
Execute git command from Python script
from subprocess import Popen, PIPE
from os import path
git_command = ['/usr/bin/git', 'status']
repository = path.dirname('/path/to/dir/')
git_query = Popen(git_command, cwd=repository, stdout=PIPE, stderr=PIPE)
(git_status, error) = git_query.communicate()
if git_query.poll() == 0:
# Do stuff
@sanfx
Copy link

sanfx commented Feb 26, 2014

Hello Nathania,

I made a git command in python, http://goo.gl/JUHJjc would you like to have some comments on it, I am going to do a version using gitPython API which i discovered after I was all done with the one using subprocess, however still debating which approach is better !

Copy link

ghost commented Oct 9, 2014

thanks~

@vickyi
Copy link

vickyi commented Nov 12, 2014

nice

@RajuKoushik
Copy link

Thanks for this !

@42piratas
Copy link

Thanks!

@jatuljain
Copy link

This was really helpful. I could create a script to completed push the code if there is any untracked files in my local with this hint

@jakubedzior
Copy link

jakubedzior commented May 5, 2020

Hello Nathania,

I made a git command in python, http://goo.gl/JUHJjc would you like to have some comments on it, I am going to do a version using gitPython API which i discovered after I was all done with the one using subprocess, however still debating which approach is better !

The link doesn't work anymore, could you please provide another one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment