The suggested way of adding all untracked files to the index in Git is to use the interactive add command:
$ git add -i staged unstaged path *** Commands *** 1: status 2: update 3: revert 4: add untracked 5: patch 6: diff 7: quit 8: help What now> a 1: testfile1.txt Add untracked>> * added one path *** Commands *** 1: status 2: update 3: revert 4: add untracked 5: patch 6: diff 7: quit 8: help What now> quit Bye.
This can be fully automated as follows:
echo -e "a\n*\nq\n"|git add -i
The commands entered via standard input (a,*,q) will not be printed. For convenience, we can also define an alias in ~/.gitconfig:
[alias] add-untracked = !"echo \"a\\n*\\nq\\n\" | git add -i"
References
- [1] Mat’s and EAGER_STUDENT’s answer on StackOverflow