自动化工具
一次性从git远程仓库中克隆到本地。
import os # git操作 将远程repo克隆到本地 def git_clone_cd_pull(url): # 获取仓库名称 如fullspider.git中,获取fullspider repository_git = os.path.splitext(os.path.split(url)[1])[0] # 定义git相关命令 cmd_git_clone = ‘git clone {url}‘.format(url=url) cmd_cd_repository_git = ‘cd {}/‘.format(repository_git) cmd_git_checkout_b_dev = ‘git checkout -b dev‘ cmd_git_branch_set = ‘git branch --set-upstream-to=origin/dev dev‘ cmd_git_pull = ‘git pull‘ # 执行命令 # 克隆 print(cmd_git_clone) os.system(cmd_git_clone) # 进入仓库目录 print(cmd_cd_repository_git) os.chdir(repository_git) # 创建dev分支,并进入分支 print(cmd_git_checkout_b_dev) os.system(cmd_git_checkout_b_dev) # 建立远程dev分支和本地dev的跟踪关系 print(cmd_git_branch_set) os.system(cmd_git_branch_set) # 下载远程仓库到本地 print(cmd_git_pull) os.system(cmd_git_pull) # 主函数 if __name__ == ‘__main__‘: url = ‘[email protected]:andy9468/fullspider.git‘ git_clone_cd_pull(url)