Skip to content

Instantly share code, notes, and snippets.

@scribu
Last active November 19, 2017 16:27
Show Gist options
  • Save scribu/4548059 to your computer and use it in GitHub Desktop.
Save scribu/4548059 to your computer and use it in GitHub Desktop.
Fixes the annoying "You can't push to X. Use Y" git error.
#!/usr/bin/env bash
# Fixes the annoying "You can't push to X. Use Y" git error.
while read -r line
do
read -a array <<< "$line"
remote="${array[0]}"
url="${array[1]}"
new_url=${url/git:\/\/github\.com\//git@github.com:}
if [ "$url" != "$new_url" ]
then
git remote set-url --push $remote $new_url
echo "Fixed url for '$remote' remote."
fi
done < <(git remote -v | grep '(push)')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment