44

So with Visual Studio 2015 just being released there is a much more integrated tie-in with git.

However the feature that seems to be lacking is git over SSH. There are various plugins for 2013 that allow this functionality (i.e GitExtensions) but I can't see any with 2015.

GitHub plugin only appears to work with GitHub and not generic git repos.

I'm not looking for an opinion of which is better, only some examples or articles to see if anyone has got Git+SSH on Visual Studio 2015 working.

John Mitchell
  • 9,653
  • 9
  • 57
  • 91

5 Answers5

49

No. Visual Studio 2015 (RTM) does not support SSH for Git remotes. This is true even with GitHub repositories using the GitHub plug-in (which - at present - uses the same connection mechanism for Git repositories as any other Git repository using Team Explorer.)

This is regrettable, but there are a handful of reasons why this is not available yet: the short answer is that in our opinion, providing SSH poorly or insecurely is worse than not providing SSH at all, and we would like to be very confident that any SSH implementation we provide is of high-quality.

That said, we are working on it, and making progress. Microsoft is going to begin including OpenSSH in Windows (and is a sponsor of that very fine project). However I cannot make any predictions as to when support might be available.

The GitHub extension is open source, so it's possible that it may be able to use a different connection mechanism and begin supporting SSH before the core Git support in Team Explorer.

Edward Thomson
  • 74,857
  • 14
  • 158
  • 187
  • Thanks! This clears it up :) Hopefully some projects will materialize to fill in the gap in the mean time. – John Mitchell Jul 22 '15 at 06:10
  • 1
    @JohnMitchell Indeed - I suspect that the GitHub extension will updated to include support independent of Team Explorer, and I updated my answer to better reflect that. – Edward Thomson Jul 22 '15 at 14:31
  • 5
    Sounds like they've let some of the IE developers into VS... :( – Alex McMillan Dec 21 '15 at 02:42
  • @EdwardThomson what's the update on this in vs 2015 update 2? – aateeque Apr 05 '16 at 00:05
  • 3
    @aateeque No change. :( – Edward Thomson Apr 05 '16 at 12:02
  • It's a shame that subsequent updates to VS2015 haven't included support for SSH in Team Explorer. Especially as SSH fixes known issues with large repositories, which Visual Studio is a huge culprit for creating. – JamieS Jul 05 '16 at 18:22
  • 1
    They've avoided "providing SSH poorly or insecurely" but have provided GIT poorly, by not including SSH. – Ronnie Overby Dec 03 '16 at 13:12
  • 2
    2017 ~ MS Can include Ubuntu in Windows 10 but still doesn't support ssh in Visual Studio? Cmon.. – Edward J Beckett Mar 04 '17 at 04:53
  • VS2017 is out and it appears that SSH is *still* not supported. Is there still not even a timeline? – Nic Aug 29 '17 at 16:14
  • @QPaysTaxes Not sure I understand - as of VS 2017, you can use ssh to connect to Git repositories in VSTS and other hosting providers. What problems are you having? – Edward Thomson Aug 29 '17 at 22:44
  • @QPaysTaxes (And if you are having problems, a new question is probably the best avenue, since comments against another answer are likely not sufficient for discussion.) – Edward Thomson Aug 29 '17 at 22:51
  • Hm. I can't get SSH to work, even after all the troubleshooting measures I could find. I'm gonna do a bit more research and see if maybe I've got an incorrect setting it a typo in something. – Nic Aug 29 '17 at 23:31
7

Here's some basic instructions for Visual Studio Update 2 and Update 3. See the link in BPas' post for the basic stuff, e.g. you'll need:

  • CMake (I used 3.5.2)
  • libssh2 (I used 1.7.0)
  • libgit2 source (grab the source from VS 2015 as noted in BPas's link)

Build libssh2

  1. I used libssh2 1.7.0. You can use older, but don't as you'll need to fix some build issues in VS2015.
  2. Do the following:

    cd <libssh2 root dir> (e.g. wherever you extracted the source to)
    mkdir build && cd build
    cmake -DCRYPTO_BACKEND=WinCNG -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTING=OFF -DBUILD_EXAMPLES=OFF ..
    
  3. Open the resulting libssh2.sln in the build directory

  4. Set the build type to "Release" (this is important!)
  5. Edit the libssh2 project, and set the calling type to __stdcall (e.g. /Gz)
  6. Rebuild all, if successful, the resulting lib will be in build/src/Release/libssh2.lib

Build libgit2

  1. Do the following:

    cd <libgit2 source dir> (e.g. this is wherever you extracted the libgit2 source you got from VS2015's extensions directory, see BPas' link for details)
    mkdir build && cd build
    cmake -DCMAKE_BUILD_TYPE=Release -DSTDCALL=ON -DSTATIC_CRT=OFF -DUSE_SSH=OFF -DLIBSSH2_FOUND=TRUE -DLIBSSH2_INCLUDE_DIRS=<libssh2 root dir>/include -DLIBSSH2_LIBRARIES=<libssh2 root dir>/build/src/Release/libssh2.lib ..
    
  2. Open the resulting libgit2.sln in the build directory

  3. Set the build type to "Release"
  4. Optional: Patch src/transports/ssh.c to support SSH RSA key authentication, in function request_creds (around line 444):

    if (!t->owner->cred_acquire_cb) {
        no_callback = 1;
    } else {
    

    with:

    if (!t->owner->cred_acquire_cb) {
        if (user) {
            const char *val = NULL;
            val = getenv("USERPROFILE");
            if (val)
            {
                char *szprivfilename = malloc(strlen(val) + 128);
                char *szpubfilename = malloc(strlen(val) + 128);
    
                strcpy(szprivfilename, val);
                strcat(szprivfilename, "/.ssh/id_rsa");
                strcpy(szpubfilename, val);
                strcat(szpubfilename, "/.ssh/id_rsa.pub");
    
                git_cred_ssh_key_new(&cred, user, szpubfilename, szprivfilename, "");
    
                free(szprivfilename);
                free(szpubfilename);
            }
            if (!cred) {
                giterr_set(GITERR_SSH, "git_cred_ssh_key_new failed to initialize SSH credentials");
                return -1;
            }
        }
        else
        {
            no_callback = 1;
        }
    } else {
    

    Note: this patch was grabbed from one the comments in randomswdev's post, seems to work fine from my limited testing.

  5. Rebuild All, output is git2.dll, replace libgit2-msvc.dll in your Visual Studio 2015 extensions directory
GSBTom
  • 71
  • 1
  • 4
  • Build libgit2,should use Release libssh2 /build/src/Release/libssh2.lib . – Boler May 24 '16 at 04:28
  • @GSBTom I don't get the part about "Edit the libssh2 project, and set the calling type to __stdcall (e.g. /Gx)". I am a c# guy so I don't understand this bit. – Gaz83 Oct 17 '16 at 18:52
  • @GSBTom, great instructions! Got me the closed ever to getting this to work, but compiling (linking?) libgit2 gives a bunch of "unresolved external symbol", all stuff like "_lib_agent_init" and other functions.. I can see them defined in in libssh2.h right in VS, but it's like the "source" of those functions was not found, even though libssh2.lib looks correctly built (no errors, file size is 376KB). Any suggestions? – jimtut Nov 22 '16 at 02:12
  • @jimtut: haven't done this in a bit (except to recompile libgit2 for Update 3), but it should work with the instructions. I'd recommend using the versions of libssh2 and CMake I used (I noticed with an older build of libssh2 I had trouble compiling and linking, its certainly possible newer versions would have problems). Make sure to be using the same build configuration (I used "Release" for both). – GSBTom Dec 01 '16 at 15:20
4

Conforming to BPas: for Visual Studio 2015 it is possible to build SSH enabled version. Moreover, i have patch for public/private key auth support:

https://github.com/PROGrand/git2-msvstfs-ssh-patch

3

It is possible to enable ssh support by recompiling the GIT library distributed with Visual Studio 2015. The following article describes the required steps:

http://randomswdev.blogspot.it/2015/07/adding-ssh-support-to-visual-studio.html

BPas
  • 99
  • 5
0

There used to be nonsense here about adding your git to visual studio using the git bash. Even though adding would work, creating commits was also an option but syncing them would still require the git bash. So this would be kinda useless.