Skip to content

Instantly share code, notes, and snippets.

@crmitchelmore
Last active October 21, 2020 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crmitchelmore/72888315549fe33119a60e739e6ff5da to your computer and use it in GitHub Desktop.
Save crmitchelmore/72888315549fe33119a60e739e6ff5da to your computer and use it in GitHub Desktop.
To update your origins to https
# Get a personal access token from github and enable SSO for it.
# Change in to the directory containing your repos
# cd /path/to/your/repo/dir
# git clone https://gist.github.com/crmitchelmore/72888315549fe33119a60e739e6ff5da
# mv 72888315549fe33119a60e739e6ff5da/update-origins.sh .
# rm -rf 72888315549fe33119a60e739e6ff5da
# chmod +x update-origins.sh
# GH_PAT=PASTyourPAThere ./update-origins.sh
# Wait :)
OLD_REMOTE="git@github.com:DigitalInnovation"
NEW_REMOTE="https://$GH_PAT@github.com/DigitalInnovation"
find "${PWD}" -type d -name '.git' | while read dir; do
cd "${dir}/.."
pwd
current_remote_url=$(git remote get-url "origin")
if grep "${OLD_REMOTE}" <<< "${current_remote_url}"; then
new_remote_url=$(sed "s~${OLD_REMOTE}~${NEW_REMOTE}~" <<< "${current_remote_url}")
echo "Changing ${current_remote_url} to ${new_remote_url}"
git remote set-url "origin" "${new_remote_url}"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment