The folder currently open doesn't have a git repository

15.9k views Asked by At

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
7

There are 7 answers

1
TWege On

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.

0
AlwaysConfused On

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

2
Hadi Masoumi On

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

0
rnwtenor On

@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.

0
situee On

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

0
SHIVAM SINGH On

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
Rolf Lader On

I worked on a remote linux server and had the same problems. I removed the local '.vscode-server' (e.g. rm -rf /home/[user]/.vscode-server) and let VS Code do a reinitialisation the next time I reconnect.