github ssh public key not found with node.js child_process.spawn() on windows, but visible on child_process.exec()

This code works on Windows and on Mac OS X:

var exec = require( 'child_process' ).exec
exec( 'git clone' )

But this code returns an “Access denied(publickey)” error from git when running on Windows, but not on Mac OS X:

  • git: fix commits from a branch created from another branch
  • A more inteligent conflict solver on git
  • Unable to connect to bitbucket using git from jenkins from tomcat installation in windows
  • “git remote show origin”: why all branches show “tracked” even when some aren't?
  • Get latest committed branch(name) details in JGit
  • Generating SSH keys (Win/msysgit) - Ruby on Rails Tutorial
  • var spawn = require( 'child_process' ).spawn
     ,  child = spawn( 'git', [ 'clone', '' ], { env: process.env } )
    child.on.stderr( 'data', function( data ) { 
      console.log( data.toString() )

    I assume in spawn i’m losing my connection to ~/.ssh… but I thought sending in process.env would work. By the way, the git clone commands work fine on Windows when typed into the command prompt directly.

    Anything obviously wrong?

  • Can git push to the current branch of a remote repository?
  • git pull --rebase - how to proceed after conflict resolution
  • Git How to: pull diff between branches
  • Docker clone private repo - Permission denied
  • Ansible hangs when pulling from vsts git repo
  • Error when deploying with git (dokku) - timeout / broken pipe
  • 2 Solutions collect form web for “github ssh public key not found with node.js child_process.spawn() on windows, but visible on child_process.exec()”

    Not a Node problem, but a git problem. Upgraded git on Windows from 1.7.11 to 1.8.3 and the spawn worked.

    I suppose the environment variables are lost in a classic node.js spaw() function, especially HOME (which isn’t defined by default in windows, and is necessary for ssh to find its keys)

    Maybe a spawn like win-spawn would work better:

    Spawn for node.js but in a way that works regardless of which OS you’re using. Use this if you want to use spawn with a JavaScript file.

    It works by explicitly invoking node on windows.
    It also shims support for environment variable setting by attempting to parse the command with a regex.
    Since all modification is wrapped in if (os === 'Windows_NT'), it can be safely used on non-windows systems and will not break anything.

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