powershell脚本批量拉取 git仓库文件

复制代码
# 定义基础URL和数据库列表  
$BASE_URL = "http://8.8.11.99:8999/yaya/"  
$DATABASES = "common-service", "bi-system", "erp", "gateway", "pdm", "plm", "public-service", "scm", "ums", "wms"  
  
# 遍历数据库列表  
foreach ($prj in $DATABASES) {  
    # 构建仓库URL和本地路径  
    $RepoURL = $BASE_URL + $prj + ".git"  
    $LocalRepoPath = ".\$prj"  
    $Dbranch = "test"  
  
    # 检查本地目录是否存在,如果不存在则克隆仓库  
    if (!(Test-Path -Path $LocalRepoPath)) {  
        Write-Host "Cloning $RepoURL to $LocalRepoPath ..."  
        git clone $RepoURL $LocalRepoPath  
        if ($LASTEXITCODE -ne 0) {  
            Write-Host "Failed to clone $RepoURL"  
        } else {  
            # 切换到特定分支并拉取更新(如果需要)  
            cd $LocalRepoPath  
            git checkout $Dbranch  
            git pull  
        }  
        cd .. # 返回到上级目录  
    } else {  
        Write-Host "Repository $RepoURL already exists locally at $LocalRepoPath"  
    }  
}  
  
# 暂停以查看输出(如果需要)  
# Read-Host -Prompt "Press Enter to continue..."  
  
# 脚本结束,不需要显式退出,因为PowerShell会在执行完毕后自动退出
相关推荐
周杰伦fans4 小时前
如何将 Feature 分支同步到 Master 主分支:一次完整的 Git 合并实战
git
jiayi_19994 小时前
git创建new branch
git
__Witheart__5 小时前
通过交互式 Rebase 合并部分提交到远程分支的操作步骤
git
魔都吴所谓6 小时前
【Tools】Repo 工具完整使用手册
git
tianyuanwo6 小时前
跨 Gerrit 项目迁移分支并保留完整历史:一份可操作的 Git 指南
git·代码迁移
玄奕子6 小时前
VS Code 上传 GitHub 全流程(Windows 环境):HTTP 与 SSH 两种方案(含常见报错排查)
git·http·ssh·github·嵌入式开发
一只游鱼6 小时前
如何让本地的敏感配置文件不上传到git仓库
git·elasticsearch
渣渣馬19 小时前
shell的if多条件
git·ssh
zh_xuan19 小时前
Visual Studio 上传工程到github
ide·git·github·visual studio
AntoineGriezmann21 小时前
Git 学习笔记
git