C# PowerShell脚本上的Git命令-授权
我有一个问题,在这种情况下,最好怎么做。我想编写一个脚本,创建一个本地存储库,然后可以从VST获取并推送到TFS以创建备份 使用GitBash,我能够按照下面的说明完成这项工作C# PowerShell脚本上的Git命令-授权,c#,git,powershell,azure,tfs,C#,Git,Powershell,Azure,Tfs,我有一个问题,在这种情况下,最好怎么做。我想编写一个脚本,创建一个本地存储库,然后可以从VST获取并推送到TFS以创建备份 使用GitBash,我能够按照下面的说明完成这项工作 git clone --mirror https://github.com/exampleuser/repository-to-mirror.git cd repository-to-mirror.git git remote set-url --push origin https://github.com/exampl
git clone --mirror https://github.com/exampleuser/repository-to-mirror.git
cd repository-to-mirror.git
git remote set-url --push origin https://github.com/exampleuser/mirrored
git fetch -p origin
git push --mirror
我想在windows 10上使用ISE制作一个Powershell脚本,它也可以这样做。我安装git posh是为了能够编写命令
但是当我按照GIT()的指示编写命令时
我得到一个错误:
远程:TF401019:名称或标识符为Logic-Test1.Git的Git存储库不存在或您没有
您正在尝试的操作的权限
用户名::术语“用户名:”不能识别为cmdlet、函数、脚本文件或可操作程序的名称。检查
名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试
如何进行身份验证以便我可以克隆它?还有,有没有一种方法不必为每个命令键入身份验证?本博客提供了一个示例,介绍了如何使用powershell从VST克隆git repo,您可以检查它,然后按照它执行其他命令
首先,创建PowerShell脚本文件:
# Read configuration file
Get-Content "CloneAllRepos.config" | foreach-object -begin {$h=@{}} -process {
$k = [regex]::split($_,'=');
if(($k[0].CompareTo("") -ne 0) -and ($k[0].StartsWith("[") -ne $True)) {
$h.Add($k[0], $k[1])
}
}
$url = $h.Get_Item("Url")
$username = $h.Get_Item("Username")
$password = $h.Get_Item("Password")
# Retrieve list of all repositories
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))
$headers = @{
"Authorization" = ("Basic {0}" -f $base64AuthInfo)
"Accept" = "application/json"
}
Add-Type -AssemblyName System.Web
$gitcred = ("{0}:{1}" -f [System.Web.HttpUtility]::UrlEncode($username),$password)
$resp = Invoke-WebRequest -Headers $headers -Uri ("{0}/_apis/git/repositories?api-version=1.0" -f $url)
$json = convertFrom-JSON $resp.Content
# Clone or pull all repositories
$initpath = get-location
foreach ($entry in $json.value) {
$name = $entry.name
Write-Host $name
$url = $entry.remoteUrl -replace "://", ("://{0}@" -f $gitcred)
if(!(Test-Path -Path $name)) {
git clone $url
} else {
set-location $name
git pull
set-location $initpath
}
}
然后在配置脚本旁边创建一个配置文件:
[General]
Url=https://myproject.visualstudio.com/defaultcollection
Username=user@domain.com
Password=YourAccessToken
[General]
Url=https://myproject.visualstudio.com/defaultcollection
Username=user@domain.com
Password=YourAccessToken