Skip to content

Instantly share code, notes, and snippets.

@jetersen
Last active August 6, 2020 08:50
Show Gist options
  • Save jetersen/e3cfd41dc9053cab4ab9bad4ffae8fc8 to your computer and use it in GitHub Desktop.
Save jetersen/e3cfd41dc9053cab4ab9bad4ffae8fc8 to your computer and use it in GitHub Desktop.
Change git remote username directly in git config file
$gitConfigs = Get-ChildItem "C:\git\code" -Include config -File -Recurse -Force | Where-Object { $_.FullName -match "\.git\\config" }
$count = $gitConfigs.Count
for ($i = 0; $i -lt $count; $i++) {
$config = $gitConfigs[$i]
$content = Get-Content $config
if (($content | ForEach-Object { $_ -match 'casz/|Jetersen/'}) -contains $true) {
$content | `
ForEach-Object { $_ -ireplace 'casz/','jetersen/' -replace 'Jetersen/','jetersen/' } | `
Set-Content -Path $config
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment