Home > Software engineering >  How to execute git commands giving repository path explicitly using C# .net Core?
How to execute git commands giving repository path explicitly using C# .net Core?

Time:10-08

I want to add path for these git commands.

I have an identified repository path where I want to execute these git commands from a function which is outside that path/repository.

How can I do that using C# and .net core 3.1?

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

CodePudding user response:

You need set WorkingDirectory to the repository path. You also need call WaitForExit to run these commands synchronously.

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