c# - 如何使用 C# .net Core 执行 git 命令显式给出存储库路径?

标签 c# git asp.net-core

我想添加这些 git 命令的路径。

我有一个已识别的存储库路径,我想从该路径/存储库之外的函数执行这些 git 命令。

如何使用 C# 和 .net core 3.1 做到这一点?

string gitCommand = "git";
string gitAddArgument = @"checkout development";
string gitPull = @"pull";
Process.Start(gitCommand, gitAddArgument);
Process.Start(gitCommand, gitPull);

最佳答案

您需要将WorkingDirectory设置为存储库路径。您还需要调用 WaitForExit 来同步运行这些命令。

Process.Start(new ProcessStartInfo(gitCommand, gitAddArgument)
{
    WorkingDirectory = "path/to/repository"
})
.WaitForExit();

关于c# - 如何使用 C# .net Core 执行 git 命令显式给出存储库路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73994254/

相关文章:

c# - 从记事本保存和检索数据时遇到奇怪的事情

c# - 字典键的两个字符串

git - Git相当于 Mercurial 添加+ Mercurial 差异?

git - 致命的 : failed to read object <objectid> Interrupted system call

visual-studio-2015 - 查看project.json时显示的Microsoft Logo 是什么?

c# - UserManager.ResetPasswordAsync 上出现“无法访问已处置的对象”错误

c# - 如何将类库包含到(非 MVC)ASP.net Razor 网站中,以便我不必使用 using 语句?

c# - C#中的默认函数参数

git - 如何检查我的所有分支是否等于主分支?

c# - 如何使用 Entity Framework Core 功能来更改我的数据库?