Skip to content

Bug: git.env('GIT_SSH_COMMAND', ...) is ignored, while constructor env works #1189

Description

@flaxes

Bug: git.env('GIT_SSH_COMMAND', ...) is ignored, while constructor env works

Environment

  • simple-git: 3.36.0
  • Node.js: v22.22.0
  • OS: Ubuntu 24.04

Description

When using GIT_SSH_COMMAND to specify an SSH private key, setting it via git.env() does not affect Git commands.

However, passing the exact same environment through the env property of the simpleGit() constructor works correctly.

Because env is not part of the published TypeScript typings, the only working solution is reported as a type error.

Reproduction

This does not work:

const { simpleGit } = require('simple-git');

const git = simpleGit({
    baseDir: '/path/to/repository',
    unsafe: {
        allowUnsafeSshCommand: true,
    },
})
.env(
    'GIT_SSH_COMMAND',
    'ssh -o StrictHostKeyChecking=no -i /home/user/.ssh/id_gitlab'
);

await git.pull('origin', 'master');

Result:

GitResponseError: Could not read from remote repository.

Using the constructor instead:

const { simpleGit } = require('simple-git');

const git = simpleGit({
    baseDir: '/path/to/repository',
    unsafe: {
        allowUnsafeSshCommand: true,
    },
    env: {
        ...process.env,
        GIT_SSH_COMMAND:
            'ssh -o StrictHostKeyChecking=no -i /home/user/.ssh/id_gitlab',
    },
});

await git.pull('origin', 'master');

works correctly.

The repository is pulled successfully.

Verification

The SSH configuration itself is correct.

The following command succeeds:

ssh -o StrictHostKeyChecking=no \
    -o IdentitiesOnly=yes \
    -i /home/user/.ssh/id_gitlab \
    -T git@gitlab.com

Using the same key with ssh-agent also works:

ssh-agent bash -c 'ssh-add /home/user/.ssh/id_gitlab; git pull'

The only difference is whether GIT_SSH_COMMAND is supplied via:

  • simpleGit({ env: { ... } })
  • .env('GIT_SSH_COMMAND', ...)

Expected behavior

Both approaches should behave identically, since they are intended to configure the environment for spawned Git processes.

If constructor env is the intended approach, it should also be exposed in the TypeScript typings.

Otherwise, git.env() appears to be ignoring GIT_SSH_COMMAND in this scenario.

Is this expected behavior, or is it a bug?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions