How to git ignore everything apart from some select files and directories

52 Views Asked by At

I'm having some trouble getting my .gitignore in just the way I want it. I've looked at previous questions on StackOverflow and I've also asked ChatGPT but I just can't get the result I want.

This is for my dotfiles config that I want to be able to easily git clone from any new machine. I have a the git repo with nvim, tmux and alacritty configs + other stuff that I don't want to include, so I'm trying to ignore everything apart from these directories and children within these directories.

Here is a screenshot that includes my current .gitignore the structure of my git repo (files with a grey colour are being ignored) and a git status to prove that they are definitely being ignored: enter image description here

I want my .gitignore in a state that:

  1. Any new file added to the nvim directory is added (I will keep ignoring the lazy-lock.json), so that I can add new plugins easily
  2. ONLY the tmux/tmux.conf and tmux/plugins/tpm are NOT ignored, but the remaining directories in tmux/plugins ARE ignored (tpm is added in my .gitmodules and I want that to sync across my machines. I will install the remaining plugins using tpm)

As I said, I know there are already other questions related to this but I just can't get the exact ignore configuration I want so I need some help.

0

There are 0 best solutions below