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

GitGitignore

Git Problem Overview


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

  • .aptitude
  • .ssh/
  • .bash_rc
  • config/.hidden

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

Git Solutions


Solution 1 - Git

Just add a pattern to .gitignore

.*
!/.gitignore

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

Solution 2 - Git

.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)" `

Solution 3 - Git

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPoeView Question on Stackoverflow
Solution 1 - GitDaniel BöhmerView Answer on Stackoverflow
Solution 2 - GitNat DarkeView Answer on Stackoverflow
Solution 3 - GitslayedbyluciferView Answer on Stackoverflow