×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Bash
Posted by: Llewellyn van der Merwe
Added: Jun 20, 2017 4:07 PM
Views: 8
Tags: repo upstream
keep forked repos in sync with upstream
  1. #!/bin/bash
  2.  
  3. # keep forked repos in sync with upstream
  4.  
  5. DIR="$HOME/VDM/REPOS"
  6. cd "$DIR"
  7. repos=($(ls -d -- */))
  8.  
  9. for folder in "${repos[@]}"; do
  10.     cd "$DIR/$folder"
  11.     echo "@ $folder"
  12.     git admin fetch upstream
  13.     onBranch=$(git symbolic-ref --short -q HEAD)
  14.     git reset --hard upstream/"$onBranch"
  15.     git clean -f -d
  16.     echo "reset $onBranch to upstream/$onBranch"
  17.     git admin push origin "$onBranch"
  18.     echo "pushed to origin $onBranch"
  19.     branches=($(git branch | awk -F ' +' '! /\(no branch\)/ {print $2}'))
  20.     echo "local branches are ${branches[@]}"
  21.     for tak in "${branches[@]}"; do
  22.         if [[ "$tak" != "$onBranch" ]]
  23.         then
  24.             git checkout "$tak"
  25.             git reset --hard upstream/"$tak"
  26.             git clean -f -d
  27.             echo "reset $tak to upstream/$tak"
  28.             git admin push origin "$tak"
  29.             echo "pushed to origin $tak"
  30.         fi
  31.     done
  32. done