diff options
Diffstat (limited to 'scripts/util/git-repo-add.sh')
-rwxr-xr-x | scripts/util/git-repo-add.sh | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/scripts/util/git-repo-add.sh b/scripts/util/git-repo-add.sh new file mode 100755 index 0000000..709ead0 --- /dev/null +++ b/scripts/util/git-repo-add.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +# this is to be run locally after remote script has executed + +if [ $# -ne 1 ]; then + echo -e "\nUsage: $0 'new-repo-name'\n" + exit 1 +fi + +if [ -d "$1" ]; then + echo "Directory $1 already exists. Aborting." + exit 1 +fi + + +echo -e "\nCreating new repo $PWD/$1" + +mkdir "$1" && echo "created $PWD/$1" +cd "$1" +git init && echo "initialized $1" +touch README.md && echo "created 'README.md'" +echo "init" > README.md +git add . && echo "staged $1" +git commit -m 'initial commit' && echo "commited repo" + +echo -e "\n\n" +while true; do + echo "Enter remote name and URL (press enter to finish)" + echo -e "eg. origin ssh://git@ssh.github.com:443/user/$1\n" + read -p ": " name url + + if [ -z "$name" ] && [ -z "$url" ]; then + break + fi + + if [ -z "$name" ] || [ -z "$url" ]; then + echo -e "\nYou must provide a name and url" + echo -e "eg. origin ssh://git@ssh.github.com:443/user/$1\n\n" + continue + fi + + git remote add "$name" "$url" + echo "added $name ($url)" +done + +read -p "Push to remote? (y/n): " push_choice + +if [[ "$push_choice" =~ ^[Yy]$ ]]; then + for remote in $(git remote); do + git push "$remote" --all + echo "Pushed to remote: $remote" + done +else + echo "Push aborted." +fi + +cd .. |