1

I have a repository where the .git directory is not in the same location as the files being tracked. Because of this, when I open my project folder in VS Code I get no git support.

I cannot find a place to put the environment variables. In the terminal I would just do export GIT_DIR=~/somedir/. I tried this in the VSC terminal but is only recognized for the terminal itself, not for the editor area (for example, to show which code I have changed).

I also found in settings Terminal > Integrated > Env : Linux that allows adding the environment variable to a settings.json but this is only recognized by the integrated terminal.

How do I set, in VS Code, the environment variable GIT_DIR for my project to have git working properly?

Daniel
  • 2,380
  • 29
  • 44

1 Answers1

1

The VSCode issue 77215 suggests launching VSCode itself with the right variable set:

alias dotfiles="GIT_WORK_TREE=~ GIT_DIR=$DOTFILES_DIR"
dotfiles git status
dotfiles code ~

Another approach would be to use git worktree (a different folder per branch, from a common cloned repository), but it is not yet supported by VSCode.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250