Skip to content

Instantly share code, notes, and snippets.

@davidyang013
Created October 30, 2014 00:35
Show Gist options
  • Save davidyang013/eb69a021a0ce13a2b623 to your computer and use it in GitHub Desktop.
Save davidyang013/eb69a021a0ce13a2b623 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://eyngwei@gerrit.sh.cn.ao.ericsson.se:29418/IPTV/MultiscreenClient"
if __name__ == '__main__':
get_branch(URL,DIR_FOLDER,"b_R15CP4")
@jarvissilva937
Copy link

FInd the best python tutorials here: Pythondex

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