Devid Karki
Devid Karki

Reputation: 121

Git isn't detected inside dev container in visual studio code

Git is not detected when I open dev container in VisualStudio Code even when I cloned the file from GitHub using SSH key.

Docker Desktop is working fine, also Everything is working fine as I can perform build, clean and test.
I cannot commit changes because there is not git repository.

No Git in DevContainer:
shows no git

Local filesystem with cloned files:
cloned file

I'm new to this. If anyone can help.

Upvotes: 12

Views: 9050

Answers (2)

Timmmm
Timmmm

Reputation: 97118

I had this issue if your Git repo is actually a submodule, because git can't find the actual .git directory (it isn't mounted in the Docker image).

If you go to Output->Git, you'll see a load of messages like

2023-09-19 10:18:14.820 [info] > git rev-parse --show-toplevel [1ms]
2023-09-19 10:18:14.820 [info] fatal: not a git repository: /workspaces/your_submodule/../../../.git/modules/path/to/your_submodule

I suspect there is no easy solution, other than cloning it separately.

Upvotes: 1

VonC
VonC

Reputation: 1329712

Developping inside a container means you need to Open a Git repository or GitHub PR in an isolated container volume#, in order for your container filesystem to mount the right local folder (the one with a .git in it)

https://code.visualstudio.com/assets/docs/remote/containers/architecture-containers.png

Start VS Code and run Remote-Containers: Clone Repository in Container Volume... from the Command Palette (F1).

Upvotes: 8

Related Questions