Skip to content

Instantly share code, notes, and snippets.

@henkin
Last active March 19, 2020 21:00
Show Gist options
  • Save henkin/5ca25d73c73de2ff6e85b244886c1064 to your computer and use it in GitHub Desktop.
Save henkin/5ca25d73c73de2ff6e85b244886c1064 to your computer and use it in GitHub Desktop.
Set Git remote origin to Https
#!/usr/bin/env bash
# chmod +x this script, put it in the parent directory, then call it with something like:
# for d in */; do; cd "$d" && bash ../git-to-https.sh && cd ..; done
# eg. if you have /src/repo1, /src/repo2, then put the script into /src, and run the loop from /src
# you have to run it within a separate Bash instance because it uses 'exit' :) hence `bash ../git-to-https.sh`
OUR_GIT_SERVER="gitlab.humanaedge.com"
DIRNAME=`basename $PWD`
if [[ ! -d .git ]]; then
echo "$DIRNAME not a git repo. skipping."
exit 0
fi
ORIGIN=`git remote get-url origin`
if [[ ! "$ORIGIN" =~ "$OUR_GIT_SERVER" ]]; then
echo "$DIRNAME not a $OUR_GIT_SERVER repo: $ORIGIN. skipping."
exit 0
fi
if [[ ! "$ORIGIN" =~ "git@" ]]; then
echo "$DIRNAME not a ssh remote: $ORIGIN. skipping."
exit 0
fi
HTTPS_ORIGIN=$(echo $ORIGIN | sed -e 's/^git@\(.*\):\/*\(.*\).git/https:\/\/\1\/\2.git/')
# echo "$HTTPS_ORIGIN"
git remote set-url origin "$HTTPS_ORIGIN"
echo "$DIRNAME git remote set $HTTPS_ORIGIN"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment