Skip to content

Instantly share code, notes, and snippets.

@StewMcc
Last active July 23, 2019 20:36
Show Gist options
  • Save StewMcc/4d8fd3b632e56268ee30375dde801ef7 to your computer and use it in GitHub Desktop.
Save StewMcc/4d8fd3b632e56268ee30375dde801ef7 to your computer and use it in GitHub Desktop.
Recursively cleans up all the .git repositories, down the directory tree from the powershells current location
function Use-GitCleanRecursively
{
$ErrorActionPreference= 'silentlycontinue'
$initialPath = Get-Location
Get-ChildItem -recurse -force |
Where-Object {$_.name -eq ".git"} |
ForEach-Object {
Set-Location $_.parent.FullName
Write-Output $_.parent.FullName
git clean -f -x -d
Set-Location ..
}
Set-Location $initialPath
Write-Output 'Recursively called "git clean -f -x -d" on all sub folders with .git folders'
}
Export-ModuleMember -Function Use-GitCleanRecursively
@StewMcc
Copy link
Author

StewMcc commented Jul 22, 2019

  • add this script in a folder Modules/GitCommands/ in your powershell's profile path
  • then add Import-Module GitCommands to your profile file

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