Created
March 31, 2017 17:43
-
-
Save davidrleonard/dd8b0249e9776506eceb380880c82112 to your computer and use it in GitHub Desktop.
Bash function to replace your Github HTTP remotes with a new password/access token
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Updates your git remote named `origin` with a new password if you're authenticating | |
# using basic auth (and not SSH). E.g. if you work for a corporatin with a proxy that | |
# murders your attempt to connect over SSH. | |
# | |
# How to use: | |
# | |
# 1. Put the function in your ~/.bash_profile or ~/.zshrc | |
# 2. Replace old_access_pass with your old password/access token and new_access_pass with your new password/access token | |
# 3. Run `fixremote` in any repo folder when your git push or pull fails | |
function fixremote () { | |
old_origin_url="$(git remote get-url origin)" | |
old_access_pass="XXXXXXXXXXX" | |
new_access_pass="XXXXXXXXXXX" | |
new_origin_url="${old_origin_url/$old_access_pass/$new_access_pass}" | |
echo $new_origin_url | |
git remote set-url origin $new_origin_url | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment