Last active
July 23, 2019 20:36
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Modules/GitCommands/
in your powershell's profile pathImport-Module GitCommands
to your profile file