addpushremote 644 B

123456789101112131415161718192021222324
  1. #!/bin/sh
  2. [ -z "$1" ] && echo "Error: no argument given" && exit 1
  3. git pull || exit 1
  4. fetch="$(git remote -v | grep fetch | awk '{print $2}')"
  5. reponame="$(echo "$fetch" | sed 's/^.*\///; s/\..*$//')"
  6. newpushremote="$(echo "$1" | sed "s/REPONAME/$reponame/")"
  7. if ! git remote -v | grep -q "$newpushremote"; then
  8. printf "\nAdding new push remote ...\n\n"
  9. git remote set-url origin --add --push "$newpushremote"
  10. fi
  11. if ! git remote -v | grep push | grep -q "$fetch" ; then
  12. echo "Readding fetch remote to push ...\n"
  13. git remote set-url origin --add --push "$fetch"
  14. fi
  15. git push
  16. printf "\nShowing remotes ...\n\n"
  17. git remote -v