Skip to content

Instantly share code, notes, and snippets.

@salanisor
Forked from davidyang013/checkoutcode
Created October 16, 2023 16:51
Show Gist options
  • Save salanisor/75b8fcb7a6b683e436c217610d2a79ba to your computer and use it in GitHub Desktop.
Save salanisor/75b8fcb7a6b683e436c217610d2a79ba to your computer and use it in GitHub Desktop.
GitPython Library clone code from remote and switch branch
import git,os,shutil
def get_branch(url,path,branch):
if url == None or path == None:
raise ValueError("Please assign right URL and Path")
else:
if os.path.isdir(path):
shutil.rmtree(path)
os.mkdir(path)
repo = git.Repo.clone_from(url, path, progress=None)
git_ = repo.git
git_.checkout(branch)
git_.pull("--rebase")
print git_.status()
DIR_FOLDER = "/Users/david/Desktop/MultiscreenClient"
URL = "ssh://[email protected]:29418/IPTV/MultiscreenClient"
if __name__ == '__main__':
get_branch(URL,DIR_FOLDER,"b_R15CP4")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment