Daniel C
Daniel C

Reputation: 2500

How to set GIT_DIR in VS Code?

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?

Upvotes: 4

Views: 624

Answers (1)

VonC
VonC

Reputation: 1324937

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.

Upvotes: 1

Related Questions