Chris Stryczynski
Chris Stryczynski

Reputation: 33991

How can I ignore non dotfiles (all non hidden directories, in the root of my repository) with git ignore?

I'd like to keep track of my "dotfiles". I'd like a git ignore to ignore all hidden files (file extension: .*).

Essentially the opposite of: Git: how to ignore hidden directories?

Within my .gitignore I've tried:

[^.]*

# Ignore everything
*

# Include all dot files.
!.*

Both which do not seem to work as intended.

MCVE:

mkdir .test .test2
mkdir abc abc2

echo ".keepme" > .test/.keepme
echo ".keepme" > .test2/.keepme
echo ".keepme" > abc/.keepme
echo ".keepme" > abc2/.keepme

echo "keepme" > .test/keepme
echo "keepme" > .test2/keepme
echo "keepme" > abc/keepme
echo "keepme" > abc2/keepme

git init
# attempt 1
echo "[^.]*" > .gitignore

mkdir -p .test/abc/
echo "abc" > .test/abc/abc

git add .gitignore
git commit -m "gitignore"

git add .

git status

Upvotes: 2

Views: 306

Answers (1)

Chris Stryczynski
Chris Stryczynski

Reputation: 33991

I needed to prepend a / to have it act on the root directory only.

/[^.]*

This question helped: How to exclude file only from root folder in Git

Upvotes: 1

Related Questions