For deploying files to some target (Windows) computers, I wanted to create a Python module I can feed with the necessary parameters. The module should then check if the specified repo exists in the outputpath.
a) If it doesn't exist: clone the latest commit from remote
b) If it exists: discard all local changes, pull the latest commit from the remote
A way (that at least this worked for me) would be to delete the local target folder, recreate it and clone everything again.
My code, that only works for an empty dir:
stderr: 'fatal: remote origin already exists.'
import git, os, shutil
#outputfolder there?
if not os.path.exists(MY_outputfolder):
os.makedirs(MY_outputfolder)
repowrk = git.Repo.init(MY_outputfolder)
wrkr = repowrk.create_remote('origin',MY_REMOTE_URL)
wrkr.fetch()
wrkr.pull(wrkr.refs[0].remote_head)
print("---- DONE ----")