Poe
Poe

Reputation: 3010

How to ignore all hidden directories/files recursively in a git repository?

I'd like to have Git ignore all hidden files and directories. i.e.

Is there a simple rule to cover this without specifically adding each entry?

Upvotes: 152

Views: 138936

Answers (4)

trytt
trytt

Reputation: 41

For me .* didn't work, doesn't ignore e.g. notebooks/templates/.ipynb_checkpoints/. What did work is:

/**/.*  # ignore all dotted files
/**/.*/ # ignore all dotted folders
!/.gitignore  # except `gitignore` :)

Upvotes: 2

slayedbylucifer
slayedbylucifer

Reputation: 23522

In .git/info/exclude, add this line:

.*

This will make ignoring all hidden/dot files recursively the default for every repository on the machine. A separate .gitignore file for every repo is not needed this way.

Upvotes: 27

Nat Darke
Nat Darke

Reputation: 891

.gitignore will only effect files that haven't been 'added' already.

To make new .gitignore entries affect all files

  1. Make changes to .gitignore
  2. git commit -a -m "Pre .gitignore changes"
  3. git rm -r --cached .
  4. git add .
  5. git commit -a -m "Post .gitignore changes"
  6. git status should output "nothing to commit (working directory clean)" `

Upvotes: 79

Daniel Böhmer
Daniel Böhmer

Reputation: 15411

Just add a pattern to .gitignore

.*
!/.gitignore

Edit: Added the .gitignore file itself (matters if it is not yet commited).

Upvotes: 206

Related Questions