Switch a Git remote
After a repo moves hosts or workspaces, origin still points at the old URL. Run this in the clone to update, fetch and push in one shot.
The script
Save this as switch_repo.sh in the root of your local repository:
#!/bin/bash
# Replace with the new remote URL
NEW_REMOTE_URL="git@bitbucket.org:new-workspace/new-repo.git"
echo "Updating remote origin to: $NEW_REMOTE_URL"
git remote set-url origin "$NEW_REMOTE_URL"
git remote set-url --push origin "$NEW_REMOTE_URL"
echo "Verifying new remote configuration:"
git remote -v
echo "Fetching from origin..."
git fetch origin
echo "Done. You can now proceed with your git operations."How to use it
- Set NEW_REMOTE_URL to the new SSH URL.
- Make it executable and run it:
chmod +x switch_repo.sh
./switch_repo.shOptional: Windows
Run this from Git Bash, which ships with Git for Windows.