Windows gitbash save ssh passphrase - sauter-hq/git-guidelines GitHub Wiki

Using the gitbash to work with git can be much fun. Using ssh can make thinks easier, exspecially when the passphrase is stored.

But it doesn't work out of the box. Manually the ssh-agent musst be started and via ssh-add the ssh-key musst be added.

To Automate things do the following:

requierements

  • ssh-key-pair stored in c:/Users/YOUR_USERNAME/.ssh/id_rsa
  • ssh public key uploaded in github-account
  • gitbash

Edit .bashrc or .bash_profile

open gitbash and open the editor with:

vim ~/.bashrc 

or just with any other editor. The absolute path is

C:\Users\YOUR_USERNAME\.bash_profile

add the folowing lines:

#use fix path for SSH_AUTH_SOCK so it works more then one instance of gitbash
export SSH_AUTH_SOCK="$TEMP/ssh_agent_socket"

ps | grep ssh-agent > /dev/null
RUNNING=$?;

if [ "$RUNNING" -eq "1" ] 
then
# ssh-agent is not yet running
    eval `ssh-agent -a $SSH_AUTH_SOCK`
    ssh-add
else
# ssh-agent is already running
    ssh-add 
fi
	

save and reopen gitbash.

nice you're done!