Use git over SSH in Node.js without any system git or ssh binaries.
Works in sandboxed environments (Docker containers, serverless functions, restricted CI) where you only have Node.js available.
Built on:
Some environments (e.g. minimal Docker images, sandboxed runtimes, OpenClaw agent containers) have Node.js but no git or ssh binaries. This package bridges the gap.
npm install node-git-ssh
# or
yarn add node-git-sshconst { generateKeyPair } = require('node-git-ssh');
const { privateKey, publicKey } = generateKeyPair('my-app');
console.log(publicKey);
// ssh-ed25519 AAAAC3... my-app
// → Add this to your GitHub/GitLab account SSH keysconst { clone } = require('node-git-ssh');
const fs = require('fs');
const privateKey = fs.readFileSync('/path/to/id_ed25519', 'utf8');
clone(
'git@github.com:user/repo.git',
'/local/destination',
{ privateKey, depth: 1 }
);const { fetch, push } = require('node-git-ssh');
fetch('/path/to/repo', { privateKey });
push('/path/to/repo', { privateKey, branch: 'main' });const { gitWithSSH } = require('node-git-ssh');
const result = gitWithSSH(
['log', '--oneline', '-10'],
{ privateKey, cwd: '/path/to/repo', stdio: 'pipe' }
);
console.log(result.stdout);Generates an ed25519 key pair in OpenSSH format.
- Returns
{ privateKey: string, publicKey: string } publicKeyis in OpenSSH authorized_keys format — paste it directly into GitHub/GitLab
Clones a repository.
url— SSH git URL (e.g.git@github.com:user/repo.git)destination— local pathoptions.privateKey— OpenSSH PEM private key stringoptions.depth— (optional) shallow clone depthoptions.branch— (optional) branch to clone
Fetches all remotes.
Pushes to a remote.
options.remote— default'origin'options.branch— (optional)
Runs an arbitrary git command with SSH authentication.
- Returns
{ status, stdout, stderr }
Returns the path to the bundled git binary.
Returns the path to git's libexec directory.
- dugite provides a pre-compiled git binary bundled as an npm package — no system git needed.
- A temporary shell script is written to
$TMPDIRand set asGIT_SSH. - That script calls a Node.js process using ssh2 to handle the SSH connection and authenticate with the provided key.
- git's
GIT_EXEC_PATHis pointed at dugite'slibexec/git-coreso internal git tools (likeindex-pack) are found.
The private key never touches disk as a persistent file — it's written to a temp file for the duration of the command and deleted immediately after.
- Only SSH URLs are supported (not HTTPS). For HTTPS, just use the native
httpsmodule orisomorphic-git. - Host key verification is skipped (
hostVerifier: () => true). For production use, implement proper host key pinning. - Tested on Linux (x64). Should work on macOS. Windows support depends on dugite's platform support.
MIT