Query Git programmatically in Visual Studio

We just transitioned from using TFS to using Git as our VCS. We are connected to Git and can check-in and such with ease.

But we have a Visual Studio extension that needs to be rewritten for Git. Using TFS programmatically was rather straight-forward, but I can’t get anything working with Git. The Microsoft docs are either wrong or I’m doing it wrong. For example, to get a reference to a Git repository, use TfsGitRepository and you get that via TeamFoundationGitRepositoryService. That (supposedly) exists in the Microsoft.TeamFoundation.Git.Server namespace. But when trying to add a reference, Visual Studio claims that namespace doesn’t exist; only Microsoft.TeamFoundation.Git.Controls does.

  • How to programatically do file versioning with SVN and .NET?
  • Can Git detect if two source files are essentially copies of each others?
  • How do I get Eclipse CDT to ignore files
  • How to show Repository History Graph in VS 2017?
  • Does the libgit2 project or anyone else provide sample code to demonstrate the various libgit2 functions?
  • How to push Tag to Bitbucket Git Repository in Bamboo from Cake build task?
  • Does anyone know of some reliable documentation for using Git via Visual Studio? Or how to do it?

    EDIT

    We are using Visual Studio 2015

  • CCNet multiple git repository timeout exception
  • Merging develop branch into master
  • I've pushed successfully, but I got an error message “error: failed to push…” in git
  • Single Git install, multiple environments (msys, cygwin, SourceTree, etc.)
  • Automatic updating build number before commit to git
  • Read-only check if a git working copy is behind its remote
  • One Solution collect form web for “Query Git programmatically in Visual Studio”

    The namespace you mentioned is on the TFS server API. It’s not available in the TFS Client Object Model. To work with git locally you’re going to make sure you have a local clone and then you can talk to it using either LibGit2 (unmanaged), LibGitSharp (Managed) or by invoking and parsing git.exe directly.

    Visual Studio doesn’t ship with it’s own object model for accessing Git, it really depends on these standard open source libraries. Visual Studio up to 2015 ships with a version of LibGitSharp. The next version of Visual Studio (out soon) ships with a new approach to accessing git repositories and wraps git.exe, performing actions against git out-of-process. A wrapper can be found in the Team Explorer extension folder, but I’m not sure on the support levels available on those assemblies:

    C:\Program Files (x86)\Microsoft Visual Studio\VS15Preview\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer
    

    If you need to check the available git repositories on the TFS server, you should use the REST api to query the available repo’s, then drop to cloning a local git repository after fetching the right repository to clone.

    Git Baby is a git and github fan, let's start git clone.