Skip to content

Instantly share code, notes, and snippets.

@cacharle
Created July 23, 2020 17:58
Show Gist options
  • Save cacharle/01b70563215306d6b6b16e8d5ebdb8cc to your computer and use it in GitHub Desktop.
Save cacharle/01b70563215306d6b6b16e8d5ebdb8cc to your computer and use it in GitHub Desktop.
Change github.com remote to use ssh
#!/bin/sh
[ $# -eq 0 ] && echo "Usage $0 REPOSITORY ..." && exit 1
for repo in $@; do
if [ ! -d $repo ] || [ ! -d $repo/.git ]; then
echo "$repo: Is not a repository"
continue
fi
cd $repo
origin_url=`git remote get-url origin`
if [ $? -ne 0 ]; then
echo "$repo: No remote named origin"
cd ..
continue
fi
url=`echo $origin_url | sed 's_.*/\(.*\)$_git@github.com:cacharle/\1.git_'`
echo "$repo: Changing remote url to: $url"
git remote set-url origin $url
cd ..
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment