Skip to content

Instantly share code, notes, and snippets.

@nissan
Last active February 13, 2020 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nissan/36345d18c93e4dea76a7c2f368476cfb to your computer and use it in GitHub Desktop.
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
# 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