0

I'm trying to have my .gitignore file allow certain subdirectories in my .config to be uploaded. This is how I've seen to do this for normal folders but it does not appear to working on my hidden directories.

*

!.config/
.config/**
!.config/bspwm/
!.config/htop/
!.config/mpd/
!.config/mpv/
!.config/neofetch/
!.config/polybar/
!.config/ranger/
!.config/sxhkd/
!.config/compton.conf
!.ncmpcpp
!.bash_profile
!.bashrc
!.vimrc
!.xinitrc
!.Xresources
GTA.sprx
  • 817
  • 1
  • 8
  • 24
  • Did you mean !/.config/bspwm – Lajos Arpad Dec 15 '19 at 09:31
  • Did you add the files using `git add .`? – Maroun Dec 15 '19 at 09:57
  • What's the problem? In what way it doesn't work? – phd Dec 15 '19 at 11:54
  • 1
    @LajosArpad It's the same. If there is a slash inside an ignored path `git` implicitly prepend a slash at the beginning. See https://git-scm.com/docs/gitignore#_examples: *The pattern **doc/frotz** and **/doc/frotz** have the same effect in any .gitignore file. In other words, a leading slash is not relevant if there is already a middle slash in the pattern.* – phd Dec 15 '19 at 11:56
  • [This answer](https://stackoverflow.com/a/14422549/1256452) to the second linked duplicate is particularly good as an example. – torek Dec 15 '19 at 22:37

1 Answers1

0

Ignored directories are not traversed. Exclude the directory from being ignored as well, and then ignore all its contents.

*
!.config/
.config/**
!.config/bspwm
$ git status
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        .config/

nothing added to commit but untracked files present (use "git add" to track)
Mika Feiler
  • 474
  • 3
  • 17
  • Hmmm.. something is causing this to not work. I've updated my question with my new full .gitignore file. Perhaps something is interfering later in the file? – GTA.sprx Dec 16 '19 at 04:43
  • @GTA.sprx I found an evil config in `git config --global --list` listing a `/etc/.gitignore` file – Ray Foss Nov 01 '22 at 18:24