ops通过shell脚本clone组织下所有仓库 chihqiang 2024-04-21 约 4 分钟 1318 字获取github组织下仓库12345curl --silent \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN> \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/orgs/{orgs}/repos下载代码1git clone --mirror git@github.com:{orgs}/{repos}.git总结完整代码1234567891011121314151617181920#!/bin/bashorgs="<target-orgs>"token="<YOUR-TOKEN>"# JSON数据repos_json=$(curl --silent \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer ${token}" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/orgs/${orgs}/repos)# 使用jq将JSON数组转换为行echo "${repos_json}" | jq -r '.[] | @json' | while IFS= read -r line; do # 处理每一行(也就是每个JSON对象) # 解析JSON对象以获取ssh地址和name ssh_url=$(echo "$line" | jq -r '.ssh_url') name=$(echo "$line" | jq -r '.name') dir_pat="${orgs}/${name}" echo "正在下载 ${ssh_url} 到 ${dir_pat}" git clone --mirror ${ssh_url} ${dir_pat} echo "下载完成 ${ssh_url}"done标签: git github sh分享: 复制链接 Twitter Facebookchihqiang代码与生活的点滴记录 关注← 上一篇在项目中git中常见分支及其作用下一篇 →在spring boot框架中使用mybatis操作数据库