git批量克隆仓库代码以及批量上传


批量克隆仓库脚本:

PowerShell 全选
# 仓库列表文件路径
$repoListFile = "repos.txt"

# 检查仓库列表文件是否存在
if (-not (Test-Path $repoListFile)) {
    Write-Host "仓库列表文件 ($repoListFile) 不存在,请检查文件路径。"
    exit
}

# 读取仓库 URL 列表
$repos = Get-Content $repoListFile

foreach ($repoUrl in $repos) {
    # 如果 URL 为空,跳过
    if ($repoUrl.Trim() -eq "") {
        continue
    }

    # 提取仓库名作为备份目录(假设仓库 URL 格式是 GitHub 或类似格式)
    $repoName = $repoUrl.Split("/")[-1].Replace(".git", "")  # 提取仓库名
    $backupDir = "$repoName"  # 定义备份路径

    
    Write-Host "开始克隆仓库: $repoUrl 到 $backupDir"
    
    # 克隆仓库,包括所有分支、标签和工作区文件
    git clone --recursive $repoUrl
    
    # 进入克隆的仓库目录
    cd $backupDir

    # 确保获取所有分支和标签
    git fetch --all --tags

    # 提示用户确保新仓库已部署好
    #Write-Host "请确保新仓库已部署并可以访问,接下来将仓库内容推送到新的仓库 URL。"
    
    # 拼接新的仓库 URL
    #$newRepoUrl = "$newServerUrl$repoName.git"
    #Write-Host "新仓库的 URL: $newRepoUrl"

    # 删除旧的远程仓库 URL 并设置新仓库的 URL
    #git remote set-url origin $newRepoUrl

    # 推送所有分支和标签到新的仓库
    #Write-Host "开始推送到新仓库..."
    #git push --mirror $newRepoUrl

    #Write-Host "$repoName 仓库已成功推送到新仓库!"
	
	cd ..
}
Write-Host "所有仓库迁移完成!"

批量推送仓库脚本:

PowerShell 全选
# 仓库列表文件路径
$repoListFile = "repos.txt"

# 检查仓库列表文件是否存在
if (-not (Test-Path $repoListFile)) {
    Write-Host "仓库列表文件 ($repoListFile) 不存在,请检查文件路径。"
    exit
}

# 读取仓库 URL 列表
$repos = Get-Content $repoListFile

foreach ($repoUrl in $repos) {
    # 如果 URL 为空,跳过
    if ($repoUrl.Trim() -eq "") {
        continue
    }
	
	# 提取仓库名作为备份目录(假设仓库 URL 格式是 GitHub 或类似格式)
    $repoName = $repoUrl.Split("/")[-1].Replace(".git", "")  # 提取仓库名
	$backupDir = "$repoName"  # 定义备份路径
    # 进入克隆的仓库目录
    cd $backupDir
	
    # 提示用户确保新仓库已部署好
    #Write-Host "请确保新仓库已部署并可以访问,接下来将仓库内容推送到新的仓库 URL。"
    
    # 拼接新的仓库 URL
    $newRepoUrl = "ssh://git@gitlab.**.com/mycode/$repoName.git"
    Write-Host "新仓库的 URL: $newRepoUrl"

    # 删除旧的远程仓库 URL 并设置新仓库的 URL
    git remote set-url origin $newRepoUrl

    # 推送所有分支和标签到新的仓库
    Write-Host "开始推送到新仓库..."
    git push --mirror $newRepoUrl

    Write-Host "$repoName 仓库已成功推送到新仓库!"
	
	cd ..
}
Write-Host "所有仓库迁移完成!"

 

repos.txt示例:

C# 全选
http://127.0.0.1/MyCode/Project1.git
http://127.0.0.1/MyCode/Project2.git
http://127.0.0.1/MyCode/Project3.git

 

 

版权声明:本文为YES开发框架网发布内容,转载请附上原文出处连接
张国生
上一篇:nginx反向代理https
下一篇:Jenkins工具配置
评论列表

发表评论

评论内容
昵称:
关联文章

git批量克隆仓库代码以及批量
GIT Bash 简单讲解-git如何推/拉代码
如何从Gitblit服务器恢复Git仓库:不需要重新部署
git仓库子模块(submodule)项目中的实战应用
html+js文件
git删除全部提交历史,成为一个新的仓库
文件图片组件使用
C# RestSharp和下载图片
GIT彻底删除文件以及历史记录
页面快排插件配置支持图片
批处理nuget包脚本
账套克隆功能实现
git 放弃本地修改
VS打包的nuget包无法nuget官网
git rebase 找回丢失的代码
VS调试运行ASP.NET MVC项目,静态资源图片404问题,Debug路径
git 合并多次提交
dotnet 将自动代码格式化机器人带入团队 GitLab 平台
批处理bat共享文件夹自动对比文件如果有更新就,实现一键发布版本
C#代码编码规范手册 软件开发规范 开发指南

联系我们
联系电话:15090125178(微信同号)
电子邮箱:garson_zhang@163.com
站长微信二维码
微信二维码