git: How do I recursively add all files in a directory subtree that match a glob pattern?

Phương Nguyễn picture Phương Nguyễn · Feb 8, 2010 · Viewed 73.2k times · Source

I have several .screen files inside /xxx/documentation and its subdirectories that are already tracked by Git.

After modifying many of these screen files, I run git add documentation/\\*.screen—as indicated by the first example in git-add's documentation—to stage these files, but the command fails:

fatal: pathspec 'documentation/\*.screen' did not match any files

Is my command bad, or does git have a bug?

Answer

Greg Bacon picture Greg Bacon · Feb 8, 2010

It's a bug in the documentation. Quote the asterisk with

$ git add documentation/\*.screen

or

$ git add 'documentation/*.screen'

to get the behavior you want.

If instead you want to add files in the current directory only, use

$ git add *.screen

UPDATE: I submitted a patch that corrects the issue, now fixed as of version 1.6.6.2.