Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gitignore all folders beginning with a period

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

I can't figure out the syntax, though I'm sure it's simple.

How's it done?

like image 408
cjm2671 Avatar asked Apr 28 '16 15:04

cjm2671


People also ask

Can Gitignore ignore folders?

gitignore is a plain text file in which each line contains a pattern for files or directories to ignore. It uses globbing patterns to match filenames with wildcard characters. If you have files or directories containing a wildcard pattern, you can use a single backslash ( \ ) to escape the character.

How do I Gitignore everything?

You want to use /* instead of * or */ in most cases The above code would ignore all files except for . gitignore , README.md , folder/a/file. txt , folder/a/b1/ and folder/a/b2/ and everything contained in those last two folders.

Does order of Gitignore matter?

The order of the rules in . gitignore doesn't seem to matter either.


2 Answers

Use one of these patterns:

# 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 the files which starts with .

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

A demo can be found in this answer:
Git: how to ignore hidden files / dot files / files with empty file names via .gitignore?

like image 124
CodeWizard Avatar answered Oct 03 '22 03:10

CodeWizard


.*/ will match everything 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

like image 41
Vampire Avatar answered Oct 03 '22 03:10

Vampire