Search code examples
visual-studiovisual-studio-2017visual-studio-extensionsvs-extensibility

How to call git-fetch from Visual Studio Extension?


I'm developing custom VS extension that will add some more UI to git source control plugin in Visual Studio. The UI is done.

Is there some API in Visual Studio SDK that I can use to invoke git related commands (git fetch for example) or to retrieve git related settings, e.g repository url?


Solution

  • You could call git command through C# code with Process. Please refer to following sample code.

    string gitCommand = "git";
    string gitAddArgument = @"add -A" ;
    string gitCommitArgument = @"commit ""explanations_of_changes"" "
    string gitPushArgument = @"push our_remote"
    
    Process.Start(gitCommand, gitAddArgument );
    Process.Start(gitCommand, gitCommitArgument );
    Process.Start(gitCommand, gitPushArgument );
    

    And you also could try use LibGit2Sharp NuGet package which is a native Git implementation. About how to use it in C#, please refer to below blog.

    http://blog.somewhatabstract.com/2015/06/22/getting-information-about-your-git-repository-with-c/