Files
dotfiles/.config/zsh/autoload/git/git-https-and-ssh

21 lines
555 B
Bash
Executable File

#!/bin/sh
#!/usr/bin/zsh
# Sets up origin so that it fetches over https but pushes over ssh. This way
# unlocking the ssh key is only needed when really necessary.
GIT="git"
origin="$($GIT remote get-url origin)"
if [ "${origin##https://}" = "$origin" ]; then
https_origin="${origin##*@}"
https_origin="https://${https_origin/://}"
$GIT remote set-url origin "$https_origin"
$GIT remote set-url --push origin "$origin"
else
ssh_origin="${origin##https://}"
ssh_origin="git@${ssh_origin/\//:}"
$GIT remote set-url --push origin "$ssh_origin"
fi