Skip to content

Instantly share code, notes, and snippets.

@jobwat
Created June 5, 2024 06:41
Show Gist options
  • Save jobwat/a351c51131ecb6b40e37fdcece56a076 to your computer and use it in GitHub Desktop.
Save jobwat/a351c51131ecb6b40e37fdcece56a076 to your computer and use it in GitHub Desktop.
git alias to update current repository password in osxkeychain
# ...
[alias]
# ...
echo-remote-proto-and-host = "!f(){ REMOTE=origin; git remote -v | grep $REMOTE | head -n1 | sed -E \"s/^$REMOTE\\t+([a-z]+):\\/\\/([^\\/]+).*/protocol=\\1\\nhost=\\2/\";};f"
clear-credentials = "!f(){ git echo-remote-proto-and-host | git credential-osxkeychain erase ;};f"
get-credentials = "!f(){ git echo-remote-proto-and-host | git credential-osxkeychain get ;};f"
update-password = "!f(){ (git echo-remote-proto-and-host; git get-credentials) | sed \"s/password=.*/password=$1/\" | git credential-osxkeychain store ;};f"
# Usage:
#. Copy your new password in clipboard
# git update-password $(pbpaste)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment