Skip to content

Instantly share code, notes, and snippets.

@nathanbedford
Last active March 28, 2017 22:58
Show Gist options
  • Select an option

  • Save nathanbedford/4e126e81d9ff183cf68e to your computer and use it in GitHub Desktop.

Select an option

Save nathanbedford/4e126e81d9ff183cf68e to your computer and use it in GitHub Desktop.
Reinitializes all the git repositories in a given folder. Is recursive by default.
$gitProjectsFolder = "c:\stash"
"Building up folder list. This may take a minute..."
# this will search for git repos up to 4 levels deep
# (not using -Depth so we can support Powershell v4)
$projectFolders = Get-ChildItem $gitProjectsFolder\*,$gitProjectsFolder\*\*,$gitProjectsFolder\*\*\*,$gitProjectsFolder\*\*\*\* -Hidden -Directory
function DeleteIfExists($file){
If(Test-Path $file){
Remove-Item $file -Force
}
}
foreach ($folder in $projectFolders )
{
If( $folder.FullName.EndsWith(".git")){
DeleteIfExists "$folder.FullName\hooks\prepare-commit-msg"
DeleteIfExists "$folder.FullName\hooks\prepare-commit-msg.cmd"
& 'git' "init" "$($folder.Parent.FullName)"
}
}
@nathanbedford
Copy link
Author

Updated to remove old hooks first, so we can spread new hook changes easily to all repos

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment