A way of generating differences against your .gitignore in one go from all the executable files from current dir:
find . -perm /111 -type f | sed 's#^./##' | sort | diff -u .gitignore -
this generates a diff meaning you don't lose any manual changes to the file. This assumes your .gitignore file is already sorted. The sed part just strips the leading ./ that find generates.
There's no automatic way to ignore only executable files, so you're always going to have to man-manage the file.
Most developers usually have a build directory in their project where the actual build process in run.
So, all executables, .o, .so, .a, etc. are there and this build directory is added into the .gitignore.
I too was trying to figure out this very question several times. Wanna share a solution that stuck for long. Though I am writing this from the Go perspective, but otherwise I believe this is generally applicable.
First, the observation is that there are much fewer executables (and/or binary) files in typical project, then everything else. Also, worth noting, that the approach to instead explicitly mark source files "to not ignore", and ignore everything else, doesn't work well, because we want our comments and text files, e.g., be git'ed too.
So the solution was to make a convention that executables have .e suffix, and .gitignore has *.e in it.
If you happen to have a "project" with quite a lot of executables, for instance, a study project where have a lot of small exercises that result get compiled, you can use this single-liner to update your .gitignore:
for f in $(find . -perm /111 -type f | grep -v '.git' | sed 's#^./##' | sort -u); do grep -q "$f" .gitignore || echo "$f" >> .gitignore ; done
ignore all c, c++ executable files save this in .gitignore file this will ignore all files without file extension cause generally there is no file extension of c/c++ executables in linux