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 the ssh-key to my ssh-agent. I have setup a ssh remote repo.

  • How can I get my git (msysgit on windows) post-commit script to invoke my python script as python rather than bash?
  • bash - Switch git protocol for multiple git repository via bash
  • unable to look up https fatal error when push to git repository
  • Translate parse_git_branch function to zsh from bash (for prompt)
  • Piping the Results of git status to Subsequent Commands
  • Unable to use bash script to remove files from git history
  • #!/bin/bash    
    cd ../ssh/
    eval $(ssh-agent)
    ssh-add id.rsa
    cd ../htdocs/

    Execute command-


    It returns

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

    When I git push origin master, it fails.
    But when I manually cd in the ssh directory, and run the same ssh-related commands and cd back to my directory htdocs and git push to origin master, it works.

    Why is this happening?

  • How to avoid exposing secret informations in vimrc when pushing it to Github
  • GitHub w/ BlueJ, I can Checkout a Project but cannot Commit Updates(or any project)
  • How to resolve git's “not something we can merge” error
  • Undo multiple file and folder 'git add'
  • extra branches created by git svn clone
  • Visual Studio 2015 Team Explorer Git branches not working properly
  • One Solution collect form web for “sh script doesn't add ssh key to ssh-agent (windows git bash)”

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

    This means that the variables set by eval $(ssh-agent) are not living beyond that shell session so the parent session doesn’t have them and cannot use the agent (also you might be spawning a new agent each time you run the script).

    The fix for this is to run that “script” in the current session by dot-sourcing the script instead of running it as an external script.

    That is you want to use .

    Git Baby is a git and github fan, let's start git clone.