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会在执行完毕后自动退出
相关推荐
JakeJiang3 小时前
Git 必备命令指南:从日常高频到项目开发实战
git
叫我少年1 天前
Windows 中安装 git
git
深海鱼在掘金6 天前
Git 完全指南 —— 第1章:Git 概览与版本控制演进
git
noravinsc7 天前
关于Git Flow
git
蜜獾云7 天前
在Git中配置用户名和密码
git
scx_link7 天前
通过git bash在本地创建分支,并推送到远程仓库中
开发语言·git·bash
南大白7 天前
IntelliJ IDEA 运行时的 JVM 本地内存溢出崩溃
git
码农小旋风7 天前
Claude Code 基础用法大全:对话、分析、修改、测试、Git 和工作流
人工智能·git·chatgpt·claude
南大白7 天前
Git 撤回提交完整方案
git
像风一样的男人@7 天前
python --实现代理服务器
git·ui