首页 > 解决方案 > 使用 http://username:password@server 的 Git Pull 仍然要求提供凭据?

问题描述

我有以下脚本,它从文件中加载凭据并使用凭据嵌入的 URL 格式进行拉取。

$remote = "http://server/repo.git"
$credential = Import-CliXml -Path 'gitcreds.xml'
Write-Host "Using credentials for $($credential.UserName)"
$url = $remote
$url = $url.Replace("http://","http://$($credential.UserName):$($credential.GetNetworkCredential().Password)@")
$url = $url.Replace("https://","https://$($credential.UserName):$($credential.GetNetworkCredential().Password)@")
Write-Host "Pulling from $($url)..."
git pull $url -f -q --progress --recurse-submodules

我正在使用它来生成凭证文件:

$credname = Read-Host "Name for the credential file? (include .xml)"
$credential = Get-Credential
$credential | Export-CliXml -Path $credname

输出更新的调试行$url看起来与我期望的完全一样 ( Pulling from http://gituser:password@server/repo.git...),但我仍然收到 Windows 凭据提示。为什么会发生,我该如何避免?

标签: gitpowershell

解决方案


推荐阅读