Reputation: 954
I am trying to track my dotfiles and config folders with git.
I set up my .gitignore
to ignore all (*) but the files and folders I want to track:
### Gitignore
# ignore all
**
!**/
# but...
# files
!.vimrc
!.Xdefault
!.bashrc
!.profile
!.xsession
!.gitignore
# folders
!.vim/**
!.config/i3/**
!.config/ranger/**
This however works only for the files, not for folders.
If I try to manually add a folder (eg. git add .config/i3
) I get The following paths are ignored by one of your .gitignore files: .config/i3 Use -f if you really want to add them
.
Upvotes: 3
Views: 283
Reputation: 1329722
If you ignore all: **
, you need to whitelist folders before being able to exclude files (because if a folder is ignored, its content won't be examined for exclusion)
So:
**
!**/
Then you can add files exclusions:
# but
# files (eg)
!.Xdefaults
!.vimrc
# etc
# folders (eg)
!./.vim/**
!./.config/ranger/**
!./.config/i3/**
Check with git check-ignore -v -- a/file
that those rules do apply.
Upvotes: 1