Simple-git在每个git命令上请求用户名和密码

时间:2019-03-08 11:08:38

标签: git git-credential-manager

这是问题https://www.npmjs.com/package/simple-git。我正在使用npm模块simple-git与本地git-repository一起工作。本地git存储库已经在本地签出,我可以通过git-bash使用该存储库(commit / push / pull所有工作)。 在同一时间,通过simple-git在同一存储库上执行的任何命令都要求我每次输入用户名和密码。

如何使simple-git使用我现有的凭据并停止在每个git命令上要求我输入用户名和密码?

PS初始化simple-git时,我只提供存储库的路径。这应该足够了,并且应该使用.git / config文件。也许需要对此.git / config中的内容进行设置/,以使其停止输入用户名和密码。

1 个答案:

答案 0 :(得分:0)

recommended way将使用凭据登录clone存储库(因此,远程服务器将已经包含用户名和密码)。

如果存储库已经被克隆,并且您不想弄乱远程服务器,则可以将URL和证书一起传递给git命令。这是push的示例。

const remotes = await git.getRemotes(true);
if (remotes.length) { // Otherwise it's a local repository, no push
    let remote = remotes[0].name; 
    if (remotes[0].refs.push.indexOf("@") < 0) { // credentials aren't in the remote ref
        remote = remotes[0].refs.push.replace("://", `://${USER}:${PASSWORD}@`);
    }
    const pushRes = await git.push(remote, "master");
}