Home > Enterprise >  How to add only all dot files and directories to a git repo?
How to add only all dot files and directories to a git repo?

Time:12-19

How to add only all dot files to a git repo? I tried:

$ gitc add .*
fatal: ..: '..' is outside repository

Also, how to add only all dot directories recursively in git, except for .mozilla?

CodePudding user response:

This is best handled with a .gitignore, then you can safely use git add ..

It can be simplest to write it inside out: ignore everything, then unignore selectively.

/*/
!/.*/
!.gitignore
/.mozilla/
  1. Ignore everything at the top level.
  2. Unignore top level directories which start with a dot.
  3. Unignore any .gitignore files.
  4. Unignore a top level .mozilla directory.

Here's a test directory.

.
├── .gitignore
├── .mozilla
│   └── no
├── .no
├── .yes
│   ├── .gitignore
│   ├── .mozilla
│   ├── .yes
│   └── yes
└── no

And here is what git add . sees.

    new file:   .gitignore
    new file:   .yes/.gitignore
    new file:   .yes/.mozilla
    new file:   .yes/.yes
    new file:   .yes/yes
  •  Tags:  
  • git
  • Related