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

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:

  • Git setup for a collection of apps sharing volatile code
  • What does the git documentation mean by 'unwrapped subject and body' for %B pretty print specifier
  • How do I get git to use Textmate as my default editor?
  • GIT pull from a bare repository
  • How does git know when there is change in the local repo?
  • How can I download only the necessary parts of a remote project in Git?
  • fatal: pathspec 'documentation/\*.screen' did not match any files

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

  • files re-checked out from git repository with 'clean' filter end up with modified status
  • Bitbucket: git push error: pack-objects died of signal 13
  • Using git clean to delete an untracked directory but not delete a subdirectory in that directory
  • Bash shell script error sh: '
  • How can just set write permission (unix chmod 0777) to a folder and git commit it in windows?
  • git frontend function(ality) for smart http git in php?
  • 6 Solutions collect form web for “git: How do I recursively add all files in a directory subtree that match a glob pattern?”

    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.

    I’ve tried the accepted answer, but it didn’t worked for me.. so here’s mine just in case someone wants to get it’s job done without spending time in dissecting various aspects that might cause the problem:

    find documentation -name "*.screen" | xargs git add -u
    

    //the -u option to git-add adds to index just the files that were previously tracked and modified

    You told the shell to look for *.screen (i.e. exactly this string – which doesn’t exist – instead of what you want “all files that end with .screen). Omit the \\ so the shell can do the file name expansion for you.

    This what I just used for a similar problem of git adding all the files in a directory:

    find . | sed "s/\(.*\)/\"\1\"/g" | xargs git add 
    

    For the original question the command would be:

    find -name "*.screen" | sed "s/\(.*\)/\"\1\"/g" | xargs git add 
    

    Note that I’m dealing with the case where a fully specified file name contains spaces. Thats why my answer. Edit the portion before the first | in order to pick out different files to add.

    try

    git add ./documentation/*.screen
    

    git add *.java works for me to add recursively all the java files

    Git Baby is a git and github fan, let's start git clone.