2

I have, until recently, been maintaining version control of various coding projects on a Windows machine via git installed within Cygwin. I am now in the process of switching over to Visual Studio Code as a text editor (I am still planning to compile via the command line, at least for now).

In order to keep double installations to a minimum, I have set VS Code's git.path variable to the git executable in the Cygwin directory. However, I am having an issue that VS Code does not seem to recognize my already-existing local git working directories, even when opening folders in VS Code at the root directory level (I have searched online and only come up with discussions from a year or two ago that suggested that this is necessary). When I click on the SOURCE CONTROL tab, I see There are no active source control providers.

Is there a way to not have to clone duplicate/replacement working directories through VS Code and to force it to use the already-cloned ones? I know I can continue to use Cygwin for git, and simply use VS Code as a text editor, but I was hoping to be able to use some of VS Code's helpful git features.

AnInquiringMind
  • 653
  • 1
  • 6
  • 13

1 Answers1

1

Simply use Git for Windows instead of Cygwin: you can unzip PortableGit-2.17.0-64-bit.7z.exe anywhere you want.

Then VSCode will recognize your existing repositories without any issue.
Combine that with GitLens, and you can do most of your Git operations directly from the editor.


Note: if you really really had to use Cygwin, Microsoft/vscode issue 7998 reports (by Eric DraconPern) :

my solution was to install Git for Windows, and then use mklink to junction link the Cygwin .ssh directory to %USERNAME%/.ssh to share config and ssh key.
Then both Git will have access to the same ssh key and ssh config for multiple key usage.
Also put the Cygwin\bin path first in %PATH% environment variable.

The same issue also mention nukata/cyg-git

This provides a Git for Windows virtually. You only need Cygwin and its packages.

I had once tried the Go plugin for VSCode on Windows 10 and found that it required Git for Windows implicitly. However, it was redundant since I had already installed Cygwin and its git package. So I wrote this proxy and wrapper.

Dmitry Katsubo proposes a bash version of that same script.


If you are on Windows 10, I would recommend WSL (Windows Subsystem for Linux), where you can install Git (the Linux original version).

VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • Thanks for the response. I am not clear on why installing Git for Windows will make a difference, as I have already set VS Code's git.path to the git executable within Cygwin. Are there additional variables/options that are correctly configured by Git for Windows to allow VS Code to correctly recognize the existing local working directories? Also, I was hoping to not have two git installations with two separate configurations -- can you think of any way around this? Thanks! – AnInquiringMind Apr 11 '18 at 04:59
  • @PhysicsCodingEnthusiast You don't need Cygwin on Windows with Git. – VonC Apr 11 '18 at 05:00
  • @PhysicsCodingEnthusiast Anything you are doing with Cygwin should be available with Git for Windows. – VonC Apr 11 '18 at 05:00
  • @PhysicsCodingEnthusiast the workaround is: don't use Cygwin in the first place, copy your global .gitconfig in your %USERPROFILE% folder, and you are good to go. – VonC Apr 11 '18 at 05:01
  • 1
    Yes, that is true. Though I use Cygwin for the command line bash shell and all the conveniences it affords me. So it was natural to also use git within Cygwin, as that was previously my main interaction point with my code. – AnInquiringMind Apr 11 '18 at 05:05
  • I suppose I will install Git for Windows and see if it resolves this issue. – AnInquiringMind Apr 11 '18 at 05:13
  • @PhysicsCodingEnthusiast No need to "install": just unzip the portable archive. And you can still use bash: it is included. – VonC Apr 11 '18 at 05:22
  • So it is now working as expected with Git for Windows -- thank you! Though I am still curious as to what exactly made the difference. For instance, are there certain settings that were automatically configured by G4W that made it "compatible" with VS Code? If so, I think it would be interesting to see if manually configuring those settings would allow for VS Code to be "compatible" with Cygwin's git. – AnInquiringMind Apr 11 '18 at 05:43
  • @PhysicsCodingEnthusiast For more on why you really don't need Cygwin at all, when it comes to Git, see https://stackoverflow.com/a/45222426/6309, https://stackoverflow.com/a/25023611/6309 and my own answer https://stackoverflow.com/a/35099458/6309 – VonC Apr 11 '18 at 06:18
  • @AnInquiringMind I have updated my answer. Don't forget to read https://stackoverflow.com/help/accepted-answer. – VonC Sep 27 '18 at 06:43
  • Thanks for the updates. I have not needed to test the suggestions you provided in your updates, as I am using Git for Windows now (but still committing, etc. using Cygwin), so I am not entirely sure if they will work. Nonetheless, I have accepted your response as the answer. – AnInquiringMind Feb 27 '19 at 05:23