gitpython模块——使用python操作git
安装
pip3 install gitpython
基本使用:pull/clone
from git.repo import Repo
import os
# 从远程仓库下载代码到本地 pull/clone
download_path = os.path.join('test','t1')
# 从远程仓库将代码下载到上面创建的目录中
Repo.clone_from('https://github.com/ylpb/CMDB.git',to_path=download_path,branch='master')
更多操作
pull最新代码
# ############## 2. pull最新代码 ##############
import os
from git.repo import Repo
local_path = os.path.join('test','t1')
repo = Repo(local_path)
repo.git.pull()
获取所有分支
# ############## 3. 获取所有分支 ##############
import os
from git.repo import Repo
local_path = os.path.join('test','t1')
repo = Repo(local_path)
branches = repo.remote().refs
f