Created
July 2, 2020 13:53
-
-
Save andrexx/e475d8b06dbd647acf12861a90019a68 to your computer and use it in GitHub Desktop.
git operations by folders
This file contains hidden or 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
param ( | |
# The root directory to perform the pull in | |
$baseDir = ".", | |
# How deep down you want to look for .git folders | |
$depth = 2, | |
# The command you want to perform | |
$cmd = "status" | |
) | |
$gitFolderName = ".git" | |
function Go () { | |
# Finds all .git folders by given path, the -match "h" parameter is for hidden folders | |
$gitFolders = Get-ChildItem -Path $baseDir -Depth $depth -Recurse -Force | Where-Object { $_.Mode -match "h" -and $_.FullName -like "*\$gitFolderName" } | |
ForEach ($gitFolder in $gitFolders) { | |
# Remove the ".git" folder from the path | |
$folder = $gitFolder.FullName -replace $gitFolderName, "" | |
Write-Host "====================================================================" | |
Write-Host "Performing git $cmd in folder: '$folder'..." -foregroundColor "green" | |
# Go into the folder | |
Push-Location $folder | |
# Perform the command within the folder | |
& git $cmd | |
# Go back to the original folder | |
Pop-Location | |
} | |
} | |
function Main () { | |
Go | |
} | |
# Executes the main function | |
Main |
This file contains hidden or 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
powershell .\\gm.ps1 -cmd "pull" |
This file contains hidden or 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
powershell .\\gm.ps1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment