Last active
February 13, 2020 23:16
-
-
Save nissan/36345d18c93e4dea76a7c2f368476cfb to your computer and use it in GitHub Desktop.
Go thru a directory with multiple repository directories, fetch their latest remotes, pull the latest for current branch, if currently on a divergent branch, pull latest master and rebase this branch to master
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
# Author: Nissan Dookeran | |
# Email: nissan.dookeran@gmail.com | |
# Date: 14-02-2020 | |
# Purpose: Go thru a directory with multiple repository directories, | |
# - fetch their latest remotes | |
# - if on master branch pull the latest | |
# - if currently on a divergent branch, pull latest and rebase this branch to origin/master | |
$cwd = Get-Location | |
$fg = "DarkGreen" | |
$bg = "White" | |
foreach ($child in (Get-ChildItem -Directory | Select-Object FullName)) { | |
$loc = $child.FullName | |
Set-Location $loc; | |
$origin = git config --get remote.origin.url | |
$currentBranch = git rev-parse --abbrev-ref HEAD | |
Write-Host "Fetching all remotes for $loc" -ForegroundColor $fg -BackgroundColor $bg | |
git fetch --all | |
if ($currentBranch -ne "master") { | |
Write-Host "Rebasing $currentBranch on master" -ForegroundColor $fg -BackgroundColor $bg | |
git pull --rebase origin master | |
} | |
else { | |
Write-Host "Pulling latest $origin/$currentBranch" -ForegroundColor $fg -BackgroundColor $bg | |
git pull | |
} | |
} | |
Write-Host "All done!" -ForegroundColor $fg -BackgroundColor $bg | |
Set-Location $cwd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment