Radivarig Radivarig - 27 days ago 14
Git Question

Why does "git add *" excludes .gitignore?

I've got .gitignore file with names of excluded files. When I delete .git folder and do

git init
, after
git add *
I would expect all files to be added that are not ignored by .gitignore. However, .gitignore shows as untracked file in
git status
and I have to manually add it with
git add .gitignore
even if I include
!.gitignore
in .gitignore.

qzb qzb
Answer

Because * in your command is actually replaced with names of files (and directories) from your current directory except ones staring w .. If you want to include also .gitignore you should call:

git add * .gitignore

If you want include all dot files call:

git add * .[!.]*

If you are using zsh, you can use simpler pattern:

 git add * .*
Comments