Skip to content

Instantly share code, notes, and snippets.

@andgineer
Created March 26, 2020 10:15
Show Gist options
  • Save andgineer/91808c22cdb14a06cd0a517521f538d4 to your computer and use it in GitHub Desktop.
Save andgineer/91808c22cdb14a06cd0a517521f538d4 to your computer and use it in GitHub Desktop.
Adding credentials to GIT remote
function gitcred () {
rep_uri=$(git config --get remote.origin.url)
rep_proto=${rep_uri:0:8}
rep_url=${rep_uri:8}
user_name=$1
user_name=${user_name:-andgineer}
user_psw=$2
user_psw=${user_psw:-???}
uri=$rep_proto$user_name:$user_psw@${rep_url#*@}
read -p "Set the URI $uri? [Y]" -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then echo "..setting"
git remote set-url origin $uri
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment