How to .gitignore everything except a few files

lindsay
1 min readMar 13, 2019

--

Recently, I wanted to add a git repo to track my dot files for fish shell, tmux, neovim. I stored the files in ~/.config and wanted to only commit the config files but nothing else.

Here is the repo: https://github.com/lynzt/dotfiles

And here’s a pic of my .gitignore:

the details:

To get this to work, you need to pattern match in your .gitignore file, but watch out for 1 thing. Reading the docs for gitignore, there’s a bullet point:

… It is not possible to re-include a file if a parent directory of that file is excluded. Git doesn’t list excluded directories for performance reasons, so any patterns on contained files have no effect, no matter where they are defined…

So, here’s how I think about this in my .gitignore file:

--

--

lindsay

this is becoming a place i list TIL… twitter: @lynzt