0

I am new to python and trying to use git commands in python script. The requirement is that I need to call some git commands like git clean and git reset commands in my python script. I need to use subprocess for this as I can't use any external libraries like GitPython.

Any help would be appreciated

Thanks.

  • 3
    `subprocess.run(["git", "clean", "-df"])` – aiven Jan 08 '18 at 09:52
  • 1
    Possible duplicate of [Calling an external command in Python](https://stackoverflow.com/questions/89228/calling-an-external-command-in-python) – max630 Jan 08 '18 at 11:49

1 Answers1

0

you can use it like below

import shlex
import subprocess 

command= "git clean -df" # you can paste any command here
comm=shlex.split(command) # This will convert the command into list format

proc=Popen(comm) # This will execute your command

for more detailed information , refer here

https://docs.python.org/2/library/subprocess.html

pankaj mishra
  • 2,555
  • 2
  • 17
  • 31