Skip to content

Instantly share code, notes, and snippets.

@silkentrance
Last active May 10, 2025 10:16
Show Gist options
  • Save silkentrance/6dba5f7547c713f736416b54c5edbae0 to your computer and use it in GitHub Desktop.
Save silkentrance/6dba5f7547c713f736416b54c5edbae0 to your computer and use it in GitHub Desktop.
Git for Windows SSH Agent
function start_ssh_agent() {
local SSH_AGENT=$(which ssh-agent 2>/dev/null)
if [ -z "${SSH_AGENT}" ]; then
return 1
fi
SSH_AUTH_SOCK=~/.ssh/ssh-agent.sock
SSH_AGENT_PID=$(ps | grep ssh-agent | tr -s ' ' | cut -f 2 -d ' ')
if [ -z "${SSH_AGENT_PID}" ]; then
eval $("${SSH_AGENT}" -a "${SSH_AUTH_SOCK}" 2>/dev/null | grep -v "echo")
fi
export SSH_AUTH_SOCK SSH_AGENT_PID
}
start_ssh_agent

This will prevent the ssh-agent from being started multiple times when using git for windows.

Will also work on linux.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment