Skip to content

Instantly share code, notes, and snippets.

@filipeandre
Created August 12, 2024 07:02
Show Gist options
  • Save filipeandre/7fe7f3feb9709102a69f93ff5305018e to your computer and use it in GitHub Desktop.
Save filipeandre/7fe7f3feb9709102a69f93ff5305018e to your computer and use it in GitHub Desktop.
Migrate gitmodules from https to ssh
#!/usr/bin/env bash
set -e
git config -f .gitmodules --get-regexp 'submodule\..*\.path' | while read -r key submodule_path; do
http_url=$(git config --file .gitmodules --get submodule.$submodule_path.url)
ssh_url=${http_url/https:\/\/github.com\//[email protected]:}
git config -f .gitmodules submodule.$submodule_path.url $ssh_url
git config -f .gitmodules submodule.$submodule_path.shallow true
echo "Updated $submodule_name ($submodule_path) URL:"
echo " From: $http_url"
echo " To: $ssh_url"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment