How can binary files be ignored in git using the .gitignore file?
Example:
$ g++ hello.c -o hello
The
To append all executables to your .gitignore (which you probably mean by "binary file" judging from your question), you can use
find . -executable -type f >>.gitignore
If you don't care about ordering of lines in your .gitignore, you could also update your .gitignore with the following command which also removes duplicates and keeps alphabetic ordering intact.
T=$(mktemp); (cat .gitignore; find . -executable -type f | sed -e 's%^\./%%') | sort | uniq >$T; mv $T .gitignore
Note, that you cannot pipe output directly to .gitignore, because that would truncate the file before cat opens it for reading. Also, you might want to add \! -regex '.*/.*/.*' as an option to find if you do not want to include executable files in subdirectories.