python操作git 安装模块 pip3 install gitpython 基本使用 import os from git.repo import Repo # 创建本地路径用来存放远程仓库下载的代码 download_path = os.path.join('NB') # 拉取代码 Repo.clone_from('https://github.com/DominicJi/TeachTest.git',to_path=download_path,branch='master') 其他常见操作 # ############## 2. pull最新代码 ############## import os from git.repo import Repo local_path = os.path.join('NB') repo = Repo(local_path) repo.git.pull() # ############## 3. 获取所有分支 ############## import os from git.repo import Repo local_path = os.path.join('NB') repo = Repo(local_path) branches = repo.remote().refs for item in branches: print(item