DEAR PEOPLE FROM THE FUTURE: Here's what we've figured out so far...

Welcome! This is a Q&A website for computer programmers and users alike, focused on helping fellow programmers and users. Read more

What are you stuck on? Ask a question and hopefully somebody will be able to help you out!
+1 vote

dotfiles link

I've cloned NvChad to $DOTFILES/config/nvim. I want to keep track of the subfolder $DOTFILES/config/nvim/lua/custom without keeping track of the rest of the nvim folder. How do I do that?


I've done

git submodule add config/nvim

to add this to /.gitmodules

[submodule "config/nvim"]
	path = config/nvim
	url =

Then I've added this to the /.gitignore



But the custom folder is not being tracked.

I had solved it by moving the custom folder outside the submodule and linking it to it's proper place. But I'd prefer to know how to make git track it without doing that. Because this way messes the structure of my dotfiles with a folder out of place.

I install my dotfiles with symlinks. Every folder in the $DOTFILES/config/ folder gets symlinked to $XDG_CONFIG_HOME. Putting the custom folder in $DOTFILES/config/custom would create a link for it and I don't want to create one. Putting it somewhere else doesn't make any sense because I want all configurations to be in the $DOTFILES/config/ folder.

I'll show the simplified tree to paint a clearer picture.

❯ tree
├── config
│   ├── alacritty
│   ├── git
│   ├── mutt
│   ├── nvim
│   │   ├── examples
│   │   ├── init.lua
│   │   ├── LICENSE
│   │   └── lua
│   │       ├── colors
│   │       ├── core
│   │       ├── custom
│   │       └── plugins
│   ├── tig
│   ├── tmux
│   ├── zathura
│   └── zsh
└── install
    ├── arch
    ├── Brewfile
    ├── debian
    └── settings

399 directories, 1836 files
edited by

I think the question is not entirely clear. What is the location of your "superproject" (the one containing your submodules)? Is /config/nvim absolute, or is it supposed to be relative to your superproject path? What .gitignore file are you editing (that of NvChad or that of your superproject)? Also, note that NvChad has a rule for "custom" in its own .gitignore.


The root / folder in this case is referring to my dotfiles folder and all the paths are relative to that folder. I don't know how to adapt my .gitignore to the fact that NvChad already adds that folder to its own .gitignore.

1 Answer

+1 vote
Best answer

I'll try to give you an answer based on how well I can understand the question. I'm making a lot of assumptions here.

Since you mentioned dotfiles, I assume that you have your dotfiles folder in some location, let's say ~/.dotfiles, and that you're trying to manage these files. The usual way of managing these files is by creating all your files inside ~/.dotfiles. For example you create the directory ~/.dotfiles/.config/nvim/lua/custom/ and then you create symlinks in the home folder to your ~/.dotfiles folder. For example ln -s ~/.dotfiles/.config/nvim/lua/custom/ ~/.config/nvim/lua/custom/ will create a symlink in the nvim folder to your dotfiles folder. This way you can pull new updates for NvChad, and you can also manage all your files within the dotfiles repository. If you have a lot of links to manage, there is a program called stow that was created for this purpose.

The other way that I understand your question is that you are trying to add the nvim folder as a submodule to your "superproject" which is located elsewhere in the filesystem. What you need is called "sparse checkout", but if you're doing dotfiles this is significantly more complex than the process that I described above. The following instructions will create a new submodule called "nvchad" in your superproject and will checkout only the "custom" folder. For this to work it requires also that you track the changes in the submodule (the nvmin folder). Since it's ignored by default, you probably want to create a new branch so that it doesn't interfere with the main branch of NvChad.

cd superproject
git submodule add ~/.config/nvim nvchad
cd nvchad
git config core.sparsecheckout true
echo lua/custom >> ../.git/modules/nvchad/info/sparse-checkout
git read-tree -mu HEAD
cd ../
git submodule update --remote    # Download updates from the submodules
selected by

I'm having trouble understanding git config core.sparsecheckout. Could you describe what it does? I want to have nvchad in /config/nvim. But when I do git submodule add $DOTFILES/config/nvim nvchad it's cloning the repository to $DOTFILES/nvchad instead. I changed it to git submodule add $DOTFILES/config/nvim.


git-sparse-checkout reduces the checkout to a set of paths. The list of paths to be checked out is in the file sparse-checkout.
Inside which directory exactly are you running git submodule add ...?


Isn't that the opposite of .gitignore? If I have to add every file in my dotfiles to that file I won't use sparse-checkout. I'm running the command from ~/Sync/config/dotfiles/


Sorry but I think I don't understand the original question then. Please tell me if this is correct:
- you have a folder at ~/Sync/config/dotfiles/ where you keep your dotfiles
- you have cloned NvChad inside nvim's configuration folder: git clone ~/.config/nvim
- you want to add ~/.config/nvim as a submodule of ~/Sync/config/dotfiles/


I've cloned NvChad inside ~/Sync/config/dotfiles/config/nvim and I only want to keep track of the custom folder and not the whole nvim folder. The custom folder is at ~/Sync/config/dotfiles/config/nvim/lua/custom.


And what do you have inside ~/.config/nvim/?


Nothing. I have set XDG_CONFIG_HOME=~/Sync/config. The nvim configuration symlink is ~/Sync/config/nvim -> ~/Sync/config/dotfiles/config/nvim/ That last path being the cloned NvChad repository.


I see. In that case what you're trying to do is not possible. Your superproject is ~/Sync/config/dotfiles and you have added ~/Sync/config/dotfiles/config/nvim/ as a submodule. To the best of my knowledge, if you change anything inside the submodule folder you will have to track the changes in the submodule itself. You cannot track them in the superproject. Git will just ignore those files. You need to change the .gitignore file of the submodule, and commit your changes in the submodule.


Ok. Then I'll remove the submodule and track only the custom folder. I will create a cronjob to pull that repository every once in a while.

Contributions licensed under CC0