Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deal with extensive .gitconfig with multiple identities and Visual Studio Code devcontainers?

It seems like Visual Studio Code and it's dev containers copy the .gitconfig upon creation. As I have to manage different identities I've quite an extensive .gitconfig, which load other configuration files conditionally. For example:

[includeIf "gitdir:~/Workspace/github.com/"]
    path = .gitconfig-github.com

Of course Visual Studio Code doesn't copy them and even if it wouldn't work as the conditional doesn't apply because it will detect the wrong directory.

Anyhow, is it somehow possible to run git config --get user.name and git config --get user.email outside of the container within the working directory and set it to the devcontainer upon creation?


Update

The problem is it's not possible to retrieve the return values from commands within a docker-compose.yml or Dockerfile to hand it over to the container right?

version: '3'

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
      args:
        VARIANT: 14
        GIT_USERNAME: ${git config --get user.name}
        GIT_USERMAIL: ${git config --get user.email}
    volumes:
      - ..:/workspace:cached
    command: sleep infinity

Something like this wouldn't work. Is there a workaround?

like image 750
Robin Avatar asked Sep 14 '25 10:09

Robin


1 Answers

As illustrated by:

  • commit 1641597 (Update docker-compose.yml files to mount .gitconfig)
  • commit 3ad0b8b (Remove .gitconfig mount now that its copied)

You would need to modify/patch the container-templates/docker-compose/.devcontainer/docker-compose.yml and others containers/xxx/.devcontainer/docker-compose.yml in order to add any instruction automatically executed by VSCode whencreating a new container.

That path would include a way to select the right config/identity to use in order to modify the mounted .gitconfig accordingly.

like image 74
VonC Avatar answered Sep 15 '25 23:09

VonC