0

I have the following script that loads credentials from a file and pulls using the credential-embedded URL format.

$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

And I'm using this to generate the credential file:

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

The debug line which outputs the updated $url looks exactly like I would expect (Pulling from http://gituser:password@server/repo.git...), but I'm still getting a Windows credential prompt. Why is it happening and how can I avoid it?

0 Answers0