C#系统命令,与GIT通信(自动记住密码)

C#系统命令,与GIT通信(自动记住密码),c#,C#,我想做一个更新的exe,当我点击它,它将下载或上传数据。问题是,每当我执行git pull origin master时,我都必须输入密码 这就是我所尝试的: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Diagnostics; namespace GitUpdate { c

我想做一个更新的exe,当我点击它,它将下载或上传数据。问题是,每当我执行
git pull origin master
时,我都必须输入密码

这就是我所尝试的:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;

namespace GitUpdate
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("GIT updating");


            Process cmd = new Process();
            cmd.StartInfo.FileName = "git";
            cmd.StartInfo.Arguments = "git pull origin master";
            cmd.StartInfo.RedirectStandardInput = true;
            cmd.StartInfo.RedirectStandardOutput = true;
            cmd.StartInfo.CreateNoWindow = true;
            cmd.StartInfo.UseShellExecute = false;
            cmd.Start();

            cmd.StandardInput.WriteLine("MY_PASSWORD_HERE");
            cmd.StandardInput.Flush();
            cmd.StandardInput.Close();
            cmd.WaitForExit();
            Console.WriteLine(cmd.StandardOutput.ReadToEnd());


            Console.WriteLine("GIT updated ...");
            Console.Read();
        }
    }
}
我做错了什么


另外,我知道有用于C#的git库和用于记住密码的选项,但我想让它成为exe样式,真的需要它。

那么,如果确实有用于此的库,为什么要采用非传统方式呢?如果你想要“exe样式”,为什么不使用其中一个库呢,并将其包装到您自己的exe中?您的git存储库是否支持直接身份验证?例如,在公司这里配置远程URL时,只需在其中添加密码。我将在其他项目中使用这种类型的程序,我需要类似于linux的
expect
,如果您听说了它,您可以在第一次推送时存储凭据(需要您手动推送,不确定在您的情况下是否可以接受)
git config credential.helper存储
。另外:为什么不制作一个bat脚本,为您节省.NETVM的开销