sbonds

Git resync fork from upstream with branches

Aug 17th, 2021 (edited)
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.86 KB | None | 0 0
  1. #!/bin/bash
  2. ## Checkout all branches from remote as tracking branches. Based on    https://stackoverflow.com/questions/379081/track-all-remote-git-branches-as-local-branches/6300386#6300386
  3.  
  4. UPSTREAM=$1
  5. MYREPO=$2
  6.  
  7. MASTERBRANCHNAME="master"
  8.  
  9. usage() {
  10.    echo "Usage:"
  11.    echo "$0 <upstream-remote> <target-remote>"
  12.    echo ""
  13.    echo "Example which ensures remote named 'maxandersen' have all the same branches and tags as 'origin'"
  14.    echo "$0 upstream origin"
  15.    exit 1
  16. }
  17.  
  18. if [ -z "$UPSTREAM" ]
  19. then
  20. echo Missing upstream remote name.
  21. usage
  22. fi
  23.  
  24. if [ -z "$MYREPO" ]
  25. then
  26. echo Missing target remote name.
  27. usage
  28. fi
  29.  
  30. git fetch $UPSTREAM
  31.  
  32. for brname in `git branch -r | grep "$UPSTREAM" | grep -v $MASTERBRANCHNAME | grep -v HEAD | sed -e 's/.*\///g'`; do git branch --track $brname  $UPSTREAM/$brname ; done
  33. git push --all $MYREPO
  34. git push --tags $MYREPO
Add Comment
Please, Sign In to add comment