Skip to content

Instantly share code, notes, and snippets.

@Justintime50
Created October 7, 2024 23:07
Show Gist options
  • Save Justintime50/297e71918dba94ec9a7d625555546078 to your computer and use it in GitHub Desktop.
Save Justintime50/297e71918dba94ec9a7d625555546078 to your computer and use it in GitHub Desktop.
Replace HTTPS URLs with SSH URLs for your Git repos recursively
#!/bin/bash
# Start from the current directory or specify the root directory as an argument
start_dir="${1:-.}"
process_config() {
local config_file="$1"
echo "Processing $config_file"
sed -i.bak 's|https://github.com/|git@github.com:|g' "$config_file"
}
export -f process_config
# Only replace .git/config content as needed
find "$start_dir" -type f -path '*/.git/config' -exec bash -c 'process_config "$0"' {} \;
echo "Deleting backups..."
find "$start_dir" -type f -name "*.bak" -delete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment