python批量克隆,新建分支,更新本地多个git仓库代码

# !/usr/bin/python
# -*- coding: utf-8 -*-
import os
__author__ = 'lidwt'

def gitclone(filepath):
    # 批量clone git仓库
    gitpaths = ["http://git.yonyou.com/young/******.git",]
    for fi in gitpaths:
        fi_d = filepath
        cmd = "cd /d %s && git clone %s " % (fi_d,fi)
        print("cmd=",cmd)
        os.system(cmd)
        print("-------------done--------------")


def gitpull(filepath):
    # 遍历filepath下所有文件
    files = os.listdir(filepath)
    for fi in files:
        fi_d = os.path.join(filepath, fi)
        cmd = "cd /d %s && git checkout %s && git pull" % (fi_d,"master")
        print("cmd=",cmd)
        os.system(cmd)
        print("-------------done--------------")

###强制使用release分支替换master分支,发版操作     
def gitpush_f(filepath):
    # 遍历filepath下所有文件
    files = os.listdir(filepath)
    for fi in files:
        fi_d = os.path.join(filepath, fi)
        cmd = "cd /d %s && git checkout master && git reset --hard release && git push origin master --force" % fi_d
        print("cmd=",cmd)
        os.system(cmd)
        print("-------------done--------------")
    
###在master分支上打tag并提交远程,发版操作 
def git_make_tag(filepath):
    # 遍历filepath下所有文件
    files = os.listdir(filepath)
    tagName ='v2019-09-09'
    tagDesc ='升级前第一次tag'
    for fi in files:
        fi_d = os.path.join(filepath, fi)
        cmd = "cd /d  " +  fi_d +" && git checkout master && git tag -a  " +  tagName +" -m  " +  tagDesc +" && git push origin  "  +  tagName
        print("cmd=",cmd)
        os.system(cmd)
        print("-------------done--------------")
        
def git_del_tag(filepath):
    # 遍历filepath下所有文件
    files = os.listdir(filepath)
    tagName ='v2019-09-09'
    for fi in files:
        fi_d = os.path.join(filepath, fi)
        cmd = "cd /d " +  fi_d +" && git checkout master && git tag -d %s  " % tagName
        print("cmd=",cmd)
        os.system(cmd)
        print("-------------done--------------")


def gitcheckout(filepath):
    # 遍历filepath下所有文件
    files = os.listdir(filepath)
    for fi in files:
        fi_d = os.path.join(filepath, fi)
        cmd = "cd /d %s && git checkout -b %s && git push --set-upstream origin %s "  % (fi_d,"demo","demo")
        print("cmd=",cmd)
        os.system(cmd)
        print("-------------done--------------")

# 递归遍历/root目录下所有文件
if __name__ == "__main__":
    path = r'D:\yonyou-D\yonyouCode-git\young'
    # gitpull(path)
    gitclone(path)
    # gitcheckout(path)#非管理员严禁执行此操作
    #gitpush_f(path)   #非管理员严禁执行此操作
    #git_make_tag(path)#非管理员严禁执行此操作
    #git_del_tag(path)  #非管理员严禁执行此操作
    
    

 

你可能感兴趣的:(it,python,git更新代码,新建分支)