3

I'm trying to figure out a rule for .gitignore file to only keep track of my dotfiles. I've tried combinations of !.* and !^.* used after * and also [^.]* as advised here. None of those ignored all of the visible, non dotfiles. What am I missing?

maciekcube
  • 61
  • 4
  • What about `*` followed by `!.*`? This seems to work for me, can you post output from your git status when it includes files you don't want? – Lasse V. Karlsen Jan 02 '20 at 13:27
  • 1
    Are you sure the problem isn't that you're already tracking non-dotfiles? – Lasse V. Karlsen Jan 02 '20 at 13:28
  • @LasseV.Karlsen Sorry, typo in my original post. I tried it and it's doing something peculiar. It ignores all non-dotfiles as intended, but also ignores some dot folders, e.g. I have a ```.config``` folder which I'm tracking (but not all the files in it) and now all the untracked files from ```.config```` folder got ignored (I may want to add them later) – maciekcube Jan 02 '20 at 13:35
  • You can always force-add files you want to track even if git is configured to ignore them. Additionally, you can add further rules in .gitignore which makes git un-ignore the files in that folder again. It is, however, not easy to build a few simple rules that does "what I think it should do". The rules are simple, so they do simple things. But you can add more rules. – Lasse V. Karlsen Jan 02 '20 at 14:33
  • https://stackoverflow.com/a/19023985/7976758 – phd Jan 02 '20 at 15:18

2 Answers2

2

Try

*
!/**/
!.*

Ignore everything, unignore all directories, unignore dotfiles.

phd
  • 82,685
  • 13
  • 120
  • 165
0
  • * ignores everything
  • !.* except dot files
  • !.*/** except any files inside dot files
*
!.*
!.*/**
s1n7ax
  • 2,750
  • 6
  • 24
  • 53