What happens, the shell extends $(...) by a bunch of words and, obviously, interprets the file with spaces embedded as several files. Even with previous suggestions for quoting the git add command, it does not work . Thus, the loop starts with incorrect arguments, as shown in this output using set -x :
ubuntu@up :~/test$ ls -1 aa ubuntu@up :~/test$ set -x; for FILE in $(git ls-files -o --exclude-standard); do git add "$FILE"; git commit -m "Added $FILE"; done + set -x ++ git ls-files -o --exclude-standard + for FILE in '$(git ls-files -o --exclude-standard)' + git add a ...
The correct solution is to tell git add $file and git ls-files NULL to separate the file names by passing -z to git ls-files and use a while loop with a zero separator:
git ls-files -o --exclude-standard -z | while read -r -d '' file; do git add "$file" git commit -m "Added $file" git push origin master done
source share