0

I know this question has been asked before but the answers didn't seem to work for me. But seemingly there's something I don't get yet.

I initialized my home directory so as to have my configs available to clone to VMs and so on.

My .git/info/exclude looks as follows:

/*
!.config/nvim*
!.config/qutebrowser/*
!.config/htop/*
!.config/emacs/*
!.config/aqemu/*
!.config/dconf/*
!.vim*
!.bash*

-> git add .

Git status output:

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
    new file:   .bash_aliases
    new file:   .bash_helper
    new file:   .bash_history
    new file:   .bash_logout
    new file:   .bashrc
    new file:   .vim/.netrwhist
    new file:   .viminfo
    new file:   .vimrc

why are my .config/x/* directories not added ? Thanks in advance and sorry if I overlooked something on the previous posts about similar topics :)

phd
  • 82,685
  • 13
  • 120
  • 165
Ceus
  • 9
  • 1
  • I've also tried: ```!.config/* .config/*``` – Ceus Nov 25 '22 at 10:30
  • Please could you give some more context? Are you planning to host your repository remotely (Github?) and then access it from your VMs? – We'll See Nov 25 '22 at 10:51
  • 1
    @Ceus Once you ignore everything with `/*` you ignore all subdirectories so Git doesn't consider `!.config/*/*` for exceptions. You should unignore subdirectories; either all subdirectories with `!*/` or specific subdirectories like `!.config/`. My second advice is to prefix everything with a slash to make them match only at the root of the repo: `!/.config/`, `!/.bash*`, etc. See https://stackoverflow.com/a/987162/7976758 , https://stackoverflow.com/search?q=%5Bgitignore%5D+ignore+everything+exception – phd Nov 25 '22 at 10:55
  • So for more context; yes I am intending to host the repo on Github – Ceus Nov 25 '22 at 12:01
  • I've tried to add the directory in: it now looks as follows:``` /* !/.config/* /.config/* !/.config/nvim* !/.config/qutebrowser/* !/.config/htop/* !/.config/emacs/* !/.config/aqemu/* !/.config/dconf/* !/.vim* !/.bash* ``` didn't work either... – Ceus Nov 25 '22 at 12:02
  • Have you tried creating a .gitignore at the root of your repository with your rules in it? [gitignore documentation](https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files) – We'll See Nov 25 '22 at 12:06
  • 1
    You must tell Git that it *must* scan `.config` at the top level. If you allow Git to *skip* `.config`, it will never look inside it, and never discover that `.config/foo/bar` should be added after all. The most direct way to do that is to add `!/.config` or `!/.config/` to the `.gitignore` anywhere below the first line to make it take effect. – torek Nov 25 '22 at 13:20
  • 1
    Using `!.config/*` is NOT SUFFICIENT because Git first skips `.config` before it finds any files or subdirectories *in* `.config`. – torek Nov 25 '22 at 13:20

0 Answers0