Sh script doesn't add ssh key to ssh-agent (windows git bash)

I am using Github for Windows on Windows 7. I have a bash script to add an ssh key to my ssh-agent. I have a remote ssh repo configured.

cd ../ssh/
eval $(ssh-agent)
ssh-add id.rsa
cd ../htdocs/


Run command -



It returns

Agent pid 5548
Identity added: id.rsa (id.rsa)


When I git push the initial master it doesn't work. But when I manually cd to the ssh directory and run the same ssh related commands and cd back to my htdocs directory and git push to the original master, it works.

Why is this happening?


source to share

1 answer

Your problem is that your script is running in its own shell session, because you are using ./


This means that the variables set eval $(ssh-agent)

do not live outside of that shell session, so the parent session does not have them and cannot use the agent (also you can create a new agent every time the script is run).

The fix for this is to run this "script" in the current session by dot-searching the script instead of running it as an external script.

That is, you want to use .




All Articles