Last active
April 17, 2020 10:09
-
-
Save dweemx/1f3caef689165e5ec7b6e2082519ba8c to your computer and use it in GitHub Desktop.
Convert SSH github clones to use HTTPS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/bin/bash | |
#-- Script to automate https://help.github.com/articles/why-is-git-always-asking-for-my-password | |
#-- Modified version of https://gist.github.com/m14t/3056747 to do the opposite | |
#-- The script iterate over all subfolder of the current working directory and | |
#-- will convert all repo/submodules to use HTTPS instead of SSH | |
for repo in `ls -d */`; do | |
cd $repo | |
REPO_URL=`git remote -v | grep -m1 '^origin' | sed -Ene's#.*([email protected]:[^[:space:]]*).*#\1#p'` | |
if [ -z "$REPO_URL" ]; then | |
echo "-- ERROR: Could not identify Repo url." | |
echo " It is possible this repo is already using SSH instead of HTTPS." | |
exit | |
fi | |
USER=`echo $REPO_URL | sed -Ene's#[email protected]:([^/]*)/(.*).git#\1#p'` | |
if [ -z "$USER" ]; then | |
echo "-- ERROR: Could not identify User." | |
exit | |
fi | |
REPO=`echo $REPO_URL | sed -Ene's#[email protected]:([^/]*)/(.*).git#\2#p'` | |
if [ -z "$REPO" ]; then | |
echo "-- ERROR: Could not identify Repo." | |
exit | |
fi | |
NEW_URL="https://github.com/$USER/$REPO.git" | |
echo "Changing repo url from " | |
echo " '$REPO_URL'" | |
echo " to " | |
echo " '$NEW_URL'" | |
echo "" | |
CHANGE_CMD="git remote set-url origin $NEW_URL" | |
`$CHANGE_CMD` | |
echo "Success" | |
cd .. | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment