2

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
Chris Stryczynski
  • 30,145
  • 48
  • 175
  • 286
  • Rather than "does not work," please edit your question to include the output of `git status` or other tools whose behavior is surprising you. – Greg Bacon Oct 12 '19 at 20:38
  • Will add a MCVE tomorrow. Thanks for the suggestion. – Chris Stryczynski Oct 12 '19 at 22:10
  • I wouldn't go for this solution, where you have a `.git` directory in your home directory. I would have a separate, actual repo, and a script to install the dotfiles into your home directory. – root Oct 13 '19 at 00:29
  • It's actually not recommended to use git to manage files in your home directory. Something like GNU Stow is a better option. It's similar to @root's suggestion but uses symbolic links. See http://brandon.invergo.net/news/2012-05-26-using-gnu-stow-to-manage-your-dotfiles.html – Yawar Oct 13 '19 at 17:01
  • I'm using the following technique https://www.atlassian.com/git/tutorials/dotfiles very simple indeed and has been working perfectly for months. – Chris Stryczynski Oct 13 '19 at 17:17

1 Answers1

1

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

Chris Stryczynski
  • 30,145
  • 48
  • 175
  • 286