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会在执行完毕后自动退出
相关推荐
Serene_Dream1 小时前
git 合并冲突的分支
git
我是一只puppy2 小时前
使用AI进行代码审查
javascript·人工智能·git·安全·源代码管理
玄同7652 小时前
Git常用命令指南
大数据·git·elasticsearch·gitee·github·团队开发·远程工作
十步杀一人_千里不留行6 小时前
Git提交前ESLint校验实践(Husky + lint-staged)
git·github
hh随便起个名9 小时前
适合小白的git的基础使用方法
git
我会一直在的9 小时前
Devps持续集成
git·ci/cd
CoderJia程序员甲10 小时前
GitHub 热榜项目 - 日榜(2026-02-08)
git·ai·开源·llm·github
Serene_Dream11 小时前
git 常用命令
git
jiayong2311 小时前
Detached HEAD 状态详解
git
李少兄21 小时前
在 IntelliJ IDEA 中修改 Git 远程仓库地址
java·git·intellij-idea