场景:项目太多了,想都拉下来看看
在gitlab项目列表页面打开控制台执行,能获取到全部项目名称
var arr=[]
for (let index = 0; index < $(".project-full-name").length; index++) {
arr.push($($(".project-full-name").get(index)).text().replace(/\n/g, ""))
}
直接通过cmd命令拉指定的项目,并拉取分支
import os
import subprocess
def download_projects(projects_list, git_base_url, local_base_path):
for project_name in projects_list:
remote_url = f"{git_base_url}/{project_name}.git"
local_path = os.path.join(local_base_path, project_name)
# 克隆远程仓库到本地
subprocess.run(["git", "clone", remote_url, local_path])
# 进入本地仓库目录
os.chdir(local_path)
# 获取远程分支列表
branches = subprocess.run(["git", "branch", "-r"], capture_output=True, text=True, encoding='utf-8').stdout.splitlines()
# 遍历远程分支并拉取代码
for branch in branches:
# 提取分支名
remote_branch = branch.strip().split("origin/")[-1]
# 切换到远程分支并拉取最新代码
subprocess.run(["git", "checkout", remote_branch])
subprocess.run(["git", "pull"])
if __name__ == "__main__":
projects_list = [
"root/project"
] # 替换为您所有项目的名称列表
git_base_url = "http://ip:port"
local_base_path = "C:\\other\\back"
download_projects(projects_list, git_base_url, local_base_path)
3095

被折叠的 条评论
为什么被折叠?



