Skip to content

Instantly share code, notes, and snippets.

@thakyZ
Last active March 6, 2021 03:43
Show Gist options
  • Select an option

  • Save thakyZ/7263988b659f2aeac2eed7cb4b0d4a95 to your computer and use it in GitHub Desktop.

Select an option

Save thakyZ/7263988b659f2aeac2eed7cb4b0d4a95 to your computer and use it in GitHub Desktop.
Command to rewrite the emails on all of your repos
$user_name = "example"
$old_email = "examplez@example.com"
$new_email = "000000+example@users.noreply.github.com"
$api = "https://api.github.com/users/$($user_name)/repos"
$j = Invoke-WebRequest $api | ConvertFrom-Json
$j | Select-Object -Property ssh_url | ForEach-Object {
git clone $_.ssh_url
}
$dir = Get-ChildItem $PSScriptRoot | Where-Object {$_.PSISContainer}
$command = "
OLD_EMAIL=`"$($old_email)`"
CORRECT_NAME=`"$($user_name)`"
CORRECT_EMAIL=`"$($new_email)`""
$command = $command +
'
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]; then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_AUTHOR_NAME="$CORRECT_NAME"
export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
'
foreach ($d in $dir) {
Set-Location $d
git filter-branch --env-filter $command --tag-name-filter cat -- --branches --tags
Set-Location ..
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment