I want to create a git repo of my bash settings and plugins and whatnot. I have ignored everything (line 0) and then manually added the files/folders that I want in the repo. (I have to do it this way because the repo is in my ~
folder.) I want to ignore all colour profiles in the .vim/colors/ directory, but I do want to include the one file that I am using (apprentice.vim).
The .vim/colors/*
line doesn't seem to work - it doesn't ignore any of the files at all. Using !!.vim/colors/*
doesn't work either. How am I supposed to make it override all previous rules and ignore the colors folder, then still allow the apprentice.vim file to be ignored?
/*
*.swp
!.gitignore
!.bashrc
!.bash_profile
!.vimrc
!.vim
.vim/colors/* # Don't include all of the other color schemes
!.vim/colors/apprentice.vim
The issue was the
# comment
on the same line as.vim/colors/*
, but here is an alternative.The main rule for gitignore is:
It is not possible to re-include a file if a parent directory of that file is excluded.
That means:
(assuming the elements are not already versioned, in which case you need to
git rm --cached
them first):**
'**/
'Result:
Check what is and is not ignored with
git check-ignore -v
(the-v
is important):It is easier than un-ignoring a sub-folder manually, especially when the sub-folder content to un-ignore is several level deep: to exclude a file in
a/b/c
, you need first to un-ignore!/a
, then!/a/b
, then!/a/b/c
)Illustration/test:
Simple
.gitignore
with/*
rule:Lets add
!.gitignore
..gitignore
can now be tracked.But if I add:
.vim
all content is still ignored:Let's check why with
git check-ignore
:Adding
!.vim
works, because it un-ignore the folder, allowing the other rules within that folder to apply.Still, this is simpler:
Your rules seem to be fine. Except
*.swp
would be covered by/*
and the comment not being on its own line.As you can see all other .vim/colors are ignored.
If your files have already been staged, you may need to unstage them and remove them from the repository, then readd them.
Final .gitignore to use