-
-
Save hannesbe/f7ad2c8bbbfa7be6f76456183539f853 to your computer and use it in GitHub Desktop.
Convert HTTPS gitlab clones to use SSH
This file contains 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 (for GitLab repos). | |
# | |
# Just run this from your clone's path: | |
# bash <(curl -Ss https://gist.githubusercontent.com/hannesbe/f7ad2c8bbbfa7be6f76456183539f853/raw) | |
REPO_URL=`git remote -v | grep -m1 '^origin' | sed -Ene's#.*(https://[^[: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#https://gitlab.com/([^/]*)/(.*).git#\1#p'` | |
if [ -z "$USER" ]; then | |
echo "-- ERROR: Could not identify User." | |
exit | |
fi | |
REPO=`echo $REPO_URL | sed -Ene's#https://gitlab.com/([^/]*)/(.*).git#\2#p'` | |
if [ -z "$REPO" ]; then | |
echo "-- ERROR: Could not identify Repo." | |
exit | |
fi | |
NEW_URL="[email protected]:$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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment