I’m tracking my dotfiles in my home directory, so I have a .git directory in my home.
Something like this.
home
└── user
├── .git
└── workspace
├── project1
│ ├── .git
│ └── main.c
├── project2
│ ├── .git
│ └── main.c
└── tmp
in the projects directories when I execute the git status
it just shows the info for that repository.
But in the tmp directory, the git walks up until it reached the home directory.
I want to disable this behavior and stop git from walking up, or at least set a limit on it.
In the terminal I can achieve this by setting the environment variable GIT_CEILING_DIRECTORIES
.
How do I do this in the vscode or more generally, how to tell git not to walk upwards?
3
Answers
When you perform
git init
inside of a folder, git already recognizes all subdirectories recursively. Since you initialized your home directory/home/user
, the.git
folder here will be the folder used by all subdirectories unless they have a.git
folder of their own.You could add all subdirectories you dont want tracked to a .gitignore file in your home directory. However,
git status
in subdirectories will still showgit status output
, so this is not the desired solution.If all you want to do is track your dotfiles, you could put all of them inside a folder called
my_dotfiles
and use this as your git repository. Then you can create symbolic links to files inside yourmy_dotfiles
in your home directory.Example for .bashrc, but you can do it for all your dotfiles:
Make sure to remove the
.git
folder from your home.Assuming vscode respects that much of Git’s configs (from what I gather it ignores quite a lot) you have to set the var in a more global environment. On systemd-based desktops that’s going to be in
~/.config/environment.d/*.conf
, (sayman environment.d
), on Windows you get to find and use whatever three-page sequence of screenshots you need to follow to get you a text box you can fiddle with this month on your Windows version.edit: @matt’s comment is worth contemplating quietly over time. If you really want to manage dotfiles or something, set up a separate git dir you explicitly call out on the command line when you’re updating, very few people want
git clean -dfx
in their home dir to wipe everything they’re not tracking.You could use a non standard
.git
directory, and use a specific wrapper to setGIT_DIR
andGIT_WORK_TREE
: