remote-merge.sh 747 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. USER=$(echo $1 | cut -d: -f1)
  5. BRANCH=$(echo $1 | cut -d: -f2)
  6. else
  7. # if $1 and $2 are not both specified, fail
  8. if [ -z "$1" ] || [ -z "$2" ]; then
  9. echo "Usage: $0 <username> <branch>"
  10. exit 1
  11. fi
  12. # provide defaults for $1 and $2 for safety anyway
  13. USER=${1:-ripmeapp}
  14. BRANCH=${2:-main}
  15. fi
  16. # Check that USER and BRANCH are not empty
  17. if [ -z "$USER" ] || [ -z "$BRANCH" ]; then
  18. echo "Usage: $0 <username> <branch>"
  19. exit 1
  20. fi
  21. LOCAL_BRANCH=$USER-$BRANCH
  22. REMOTE_BRANCH=$USER/$BRANCH
  23. git remote add $USER https://github.com/$USER/ripme.git
  24. git fetch $USER $BRANCH
  25. git checkout -B $LOCAL_BRANCH origin/main
  26. git merge $REMOTE_BRANCH