remote-branch.sh 766 B

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/bash
  2. # if $1 is user:branch, split it into $USER and $BRANCH at the :
  3. if [[ $1 == *:* ]]; then
  4. echo "Splitting $1 into user and branch"
  5. USER=$(echo $1 | cut -d: -f1)
  6. BRANCH=$(echo $1 | cut -d: -f2)
  7. else
  8. # if $1 and $2 are not both specified, fail
  9. if [ -z "$1" ] || [ -z "$2" ]; then
  10. echo "Usage: $0 <username> <branch>"
  11. exit 1
  12. fi
  13. # provide defaults for $1 and $2 for safety anyway
  14. USER=${1:-ripmeapp}
  15. BRANCH=${2:-main}
  16. fi
  17. # Check that USER and BRANCH are not empty
  18. if [ -z "$USER" ] || [ -z "$BRANCH" ]; then
  19. echo "Usage: $0 <username> <branch>"
  20. exit 1
  21. fi
  22. LOCAL_BRANCH=$USER-$BRANCH
  23. REMOTE_BRANCH=$USER/$BRANCH
  24. git remote add $USER https://github.com/$USER/ripme.git
  25. git fetch $USER $BRANCH
  26. git checkout -B $LOCAL_BRANCH $USER/$BRANCH