git bash error: / mingw64 / bin / git: Argument list too long when executing "git add *"

3

I am working on a project and I am creating the initial version by adding the base files. The problem comes when I try to add all the files in the folder (I previously created the file .gitignore with the corresponding) with the command

git add *

It takes a few seconds to show the indicated error

bash: /mingw64/bin/git: Argument list too long

It's the first time it happens to me and if I add files more specifically it does not happen.

Data from my system:

  • windows 7 professional x64 service pack 1 original
  • Core i5
  • 4gb of ram
  • git 2.16.2

Most of the files, at least 98% have no extension, but still using the following error

git add *.

If I put the name of the file or the initial does not happen:

git add O*
    
asked by Christopher Villa 08.03.2018 в 00:08
source

1 answer

4

When you do git add * you are using the Bash functionality called expansion , which means that Bash replaces the * with a list of all that element that matches that pattern. Since * matches anything, saying git add * what you're doing is git add fichero1 fichero2 ... ficheroN .

For whatever reason, probably because there are binaries, that N is very large, which causes your git add fichero1 fichero2 ... ficheroN command to contain so many elements that it exceeds the limit imposed by the kernel.

To solve it you have two options:

  • Use a loop:

    for fichero in *
    do
        git add "$fichero"
    done
    
  • Use a more restrictive pattern, to expand to a smaller number of elements:

    git add directorio1/
    git add directorio2/
    git add un_patron*
    

Recommended reading: Argument list too long error for rm, cp, mv commands

    
answered by 08.03.2018 / 08:54
source