tj.git-extras/bin/git-rename-remote
2023-02-03 09:41:36 +08:00

21 lines
428 B
Bash
Executable file

#!/usr/bin/env bash
set -euo pipefail
old=$1
new=$2
test -z "$old" && echo "old remote name required." 1>&2 && exit 1
test -z "$new" && echo "new remote name required." 1>&2 && exit 1
if ! git config --get "remote.$old.fetch" > /dev/null; then
echo "remote $old doesn't exist"
exit 1
fi
if git config --get "remote.$new.fetch" > /dev/null; then
git remote remove "$new"
fi
git remote rename "$old $new"
git remote -v