Gitignore all folders starting with a period

I want to use a .gitignore file to ignore all folders starting with a period (hidden linux folders).

I cannot understand the syntax, although I am sure it is simple.

How to do it?

+8
git
source share
3 answers

Use one of these templates:

 # ignore all . files but include . folders .* !.*/ 

 # ignore all . files and . folders .* # Dont ignore .gitignore (this file) # This is just for verbosity, you can leave it out if # .gitignore is already tracked or if you use -f to # force-add it if you just created it !/.gitignore 

 # ignore all . folders but include . files .*/ 

What is this pattern?

.* - This patter tells git to ignore all files starting with .

! . This tells git not to ignore the pattern. In your case /.gitignore

You can find a demo in this answer:
Git: how to ignore hidden files / point files / files with empty file names via .gitignore?

+11
source share

You should be able to use the double asterisk character, which represents directories at any depth.

 .**/ 
0
source share

.*/ will match anything that starts with a dot and is a folder

With the following command, you can test it: mkdir test && cd test && git init && mkdir -p .foo .foo/.bar foo/.bar && touch .foo/dummy .foo/.bar/dummy foo/.bar/dummy && git add . && git status && echo '.*/'>.gitignore && git reset && git add . && git status mkdir test && cd test && git init && mkdir -p .foo .foo/.bar foo/.bar && touch .foo/dummy .foo/.bar/dummy foo/.bar/dummy && git add . && git status && echo '.*/'>.gitignore && git reset && git add . && git status

0
source share

All Articles