9

I am working on a work PC which has a windows OS and I'm used to using ubuntu OS for rails development. I installed everything properly with wsl as ubuntu on VSCode and git for windows but the problem is the source control panel is not detecting anything and it just shows this:

Screenshot of Source Control Panel in VS Code.

How can I resolve this?

Here's my installation references.

  • Visual Studio Code https://code.visualstudio.com/
  • WSL https://learn.microsoft.com/en-us/windows/wsl/install
  • Git https://git-scm.com/download/win
KyleMit
  • 30,350
  • 66
  • 462
  • 664
JM Arenas
  • 91
  • 1
  • 1
  • 5
  • Which folder have you opened in VS Code and does it actually have a `.git` folder inside? – carlfriedrich Apr 19 '22 at 08:44
  • I opened the repo folder which I had cloned earlier and yes it does have `.git` folder inside – JM Arenas Apr 20 '22 at 03:28
  • Hmm... Maybe you can add some more details to your question. Does VS Code's explorer show the folder correctly? Where and how did you clone the repository? Are you using VS Code in remote mode connected to WSL? Maybe add a screenshot of your complete VS Code window. – carlfriedrich Apr 20 '22 at 07:29

6 Answers6

16

You need to add the repo directory as a safe directory with the recommended command:

git config --global --add safe.directory 'path/to/repo'

you can also trust any directory (But it is not really recommended)

git config --global --add safe.directory *

if you face an error like this:

error "fatal: bad config file line 1 in .git/config" 

please look at 27073427 answer

Hadi Masoumi
  • 1,153
  • 9
  • 13
6

The change probably came from the GIT security update.

The owner of the .git folder is not the same user you are running VS Code with, so the repo will not show up in VS Code.

You can change the permissions in Window as follows:

Right-click folder -> Properties -> Security -> Advanced

Here you can change the owner or add another user.

After changing the permissions, you have to restart VS Code. Now all repos should be displayed again.

TWege
  • 61
  • 2
0

@TWege solution worked for me. I closed then reopened the new remote dev container and then VSCode recognized the branch I checked out.

configuration: Windows 11; WSL2; VSCode; Remote Container Developement w/ Docker-in-Docker; Github with issue associated to branch;

Steps:

  1. Github: Created github repository with README.md
  2. Github: Added issue for setting up .devcontainers on local vscode machine
  3. Github: Created branch associated to .devcontainer issue (remember to copy the two commands presented after creating this branch [git fetch origin; git checkout [new branch name]]
  4. VSCode: Cloned remote repository to my local drive, which opened it in VSCode
  5. VSCode: Added 'Development Container Configuration Files' (for Python 3, I added Git, SSH server; and docker-in-docker)
  6. VSCode: Edit .devcontainer json and Docker files (fx, forward ports to local machine)
  7. Git (in vscode terminal - note you are still in windows or wsl2 host linux): add, commit and push to origin all changes (.devcontainer files)
  8. Git: git will prompt you the repository is owned by someonelse, so and present you with this command to run: (git config --global --add safe.directory 'path/to/repo')
  9. VSCode: 'Open in Container'
  10. Git (in new remote container): now use the two commands you received when you created the new branch in
  11. Githup: [git fetch origin; git checkout [new branch name]]
  12. VSCode: Close Remote Connection VSCode: restart local VSCode
  13. VSCode: Open new remote container you just created.

Now you should see the your git information for the new branch checked out.

rnwtenor
  • 13
  • 2
0

If you are using mac this might help-- Open your .bash_profile in your local user directory and then add the path "/usr/local/bin/git". You can open .bash_profile in vi and type PATH="/usr/local/bin/git" and save.

0

1 For windows, open C:\Users\yourusername\.gitconfig

2 Add your project path in the [safe] section, example:

[safe]
  directory = D:/path/to/your-project

3 Restart VSCode

situee
  • 2,710
  • 2
  • 22
  • 27
-2

Had the same issue, I just ran the vscode as admin and it worked

AlwaysConfused
  • 729
  • 2
  • 12
  • 37