Created
August 20, 2021 05:34
-
-
Save hackerb9/080ad30a2fe17324ae390a3fadb362b5 to your computer and use it in GitHub Desktop.
Fix existing github repository to use ssh access instead of username/password
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 | |
# A temporary script for a temporary problem. | |
# I have a bunch of github repositories that no longer work | |
# for git push because the original URL uses the deprecated | |
# username/password combo. This script repairs the remote | |
# origin so it uses ssh. | |
# B9 August 2021 | |
oldurl=$(git remote get-url origin) | |
if [[ -z "$oldurl" ]]; then | |
echo "gitfixssh error: Git can't get the remote origin URL." >&2 | |
exit 1 | |
fi | |
if [[ "$oldurl" == [email protected]:* ]]; then | |
echo "gitfixssh: Repository already set to ssh access." >&2 | |
exit 0 | |
fi | |
if [[ "$oldurl" != http*github.com/* ]]; then | |
echo "gitfixssh error: Unrecognized remote origin url: '$oldurl'." >&2 | |
exit 1 | |
fi | |
[email protected]:${oldurl#*github.com/} | |
echo "Old origin URL: '$oldurl'" | |
echo "New origin URL: '$url'" | |
echo "git remote set-url origin '$url'" | |
git remote set-url origin "$url" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment