dotfiles/.local/bin/scripts/git-upstream

14 lines
439 B
Plaintext
Raw Normal View History

#!/bin/sh
2024-02-20 18:54:51 +00:00
# Set given repository as upstream or add as a new remote
test $# -lt 1 && echo "$0 <user> [repo] [remote-name]" && exit 1
if test "$3"
then
name="$3"
git remote remove "$3" 2>/dev/null
else
2022-09-27 19:58:13 +00:00
git remote get-url upstream >/dev/null 2>&1 && name="$1" || name="upstream"
fi
origin="$(git remote get-url origin)"
2024-02-20 18:54:51 +00:00
git remote add -f "$name" "$(echo $origin | cut -d':' -f1):$1/${2:-$(echo $origin | cut -d'/' -f2)}"
git remote -v