Created
October 30, 2014 00:35
-
-
Save davidyang013/eb69a021a0ce13a2b623 to your computer and use it in GitHub Desktop.
GitPython Library clone code from remote and switch branch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
FInd the best python tutorials here: Pythondex