Skip to content

Instantly share code, notes, and snippets.

@giseongeom
Last active September 6, 2021 03:29
Show Gist options
  • Save giseongeom/6750c18b2cc48a1310088ece28f5daee to your computer and use it in GitHub Desktop.
Save giseongeom/6750c18b2cc48a1310088ece28f5daee to your computer and use it in GitHub Desktop.
Update multiple git repository's remote-url
#Requires -version 5.1
cd C:\Users\giseong.eom\Source
$repolist1 = dir -Directory -Exclude archived C:\Users\giseong.eom\Source | % { $_.FullName }
$repolist2 = (
"c:\Users\giseong.eom\.dotfiles",
"c:\Users\giseong.eom\tools"
)
$repolist = $repolist1 + $repolist2
$repo_access_user = 'giseongeom'
$repolist | % {
$target_dir = $_
Set-Location -Path $target_dir
$git_url = (((git remote -v | findstr /i fetch) -split "`\t")[1] -split " ")[0]
# Cloned via https
if ($git_url -like "*github*" -and $git_url -like "https*") {
$repo_name = ($git_url -split '/')[-1]
$repo_owner = ($git_url -split '/')[-2]
$git_url
$repo_owner
$repo_name
& git remote set-url origin "https://${repo_access_user}@github.com/${repo_owner}/${repo_name}"
& git config --replace-all --local user.name "GiSeong Eom"
& git config --replace-all --local user.email jurist@kldp.org
& git config --replace-all --local core.autocrlf false
}
# Cloned via ssh
if ($git_url -like "*github*" -and $git_url -like "git*") {
$repo_name = ($git_url -split '/')[-1]
$repo_owner = (($git_url -split '/')[-2] -split ':')[-1]
<#
& git remote set-url origin "https://${repo_access_user}@github.com/${repo_owner}/${repo_name}"
& git config --replace-all --local user.name "GiSeong Eom"
& git config --replace-all --local user.email jurist@kldp.org
& git config --replace-all --local core.autocrlf false
#>
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment