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

13 lines
448 B
Bash
Executable File

#!/bin/sh -e
# set repo as origin and set all branches upstream to a corresponding remote branch, if available
remote="${4:-origin}"
git remote $(case "$(git remote)" in
(*"$remote"*) echo set-url;;
(*) echo add;;
esac) "$remote" "$(git-repo "$@")"
git remote -v && git fetch
git branch --format='%(refname:short)' | while read branch
do test $(git branch -a | grep $remote/$branch | wc -l) -gt 0 && git branch -u $remote/$branch $branch
done