Question

I'm using Git to create a backup system.

I've just created the directory and initialized git on it.

git init

When I tried to add the untracked files to the stage with

git add -u *.pdf

I get this response error:

sh.exe": /bin/git: Bad file number

As additional information, I have a list of ~4500 untracked files and if I try to add the files one by one, I don't get any error response and the files are sent to the stage.

Does anyone know how to solve this problem and why it happens? I need to add all these untracked files, but I don't want to do that in a "monkey job" way, adding one by one.

Was it helpful?

Solution

You don't want '-u' as it will only add files that you are already tracking. After a git init you are not tracking anything yet. From the documentation:

-u, --update: Only match against already tracked files in the index rather than the working tree. That means that it will never stage new files, but that it will stage modified new contents of tracked files and that it will remove files from the index if the corresponding files in the working tree have been removed.

Use -A (or --all) instead.

For your specific problem, when you write '*.pdf' the shell expands that into 4500 files. That large number of files probably overflows the shell command line input buffer; which leads to the error. You could do a few things:

git add -A               # adds everything at once

or

for file in *.pdf; do git add -A $file; done    # add files one by one

Both of these suggestions will avoid the command line issue; the first is preferred.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top