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会在执行完毕后自动退出
相关推荐
知识即是力量ol27 分钟前
研发实战:Git 规范化开发全流程指南
git·gitee·github
我是一只代码狗33 分钟前
idea创建分支
git
知识即是力量ol2 小时前
Git 快速入门 (实习生视角)
git·gitee·github
Dontla3 小时前
Git撤销上一次提交(撤销提交,Git回退提交)git reset、git revert
git
wdfk_prog3 小时前
解决 `git cherry-pick` 引入大量新文件的问题
大数据·git·elasticsearch
fu的博客5 小时前
Git从删库到跑路
git·gitee·github
要加油哦~6 小时前
git 报错 | husky - pre-commit hook exited with code 1 解决
git
知识即是力量ol6 小时前
Git 实战指南:从分支管理到冲突解决
git·github·源代码管理
weixin_4624462319 小时前
Git 本地忽略 application-dev.yml 的最佳实践:不提交 .gitignore,不影响团队协作!
git
无限进步_1 天前
面试题 02.02. 返回倒数第 k 个节点 - 题解与详细分析
c语言·开发语言·数据结构·git·链表·github·visual studio