I’ve created a C++ file and it runs perfectly. But the problem comes when I push my code to GitHub. There is an executable file as the result of building my C++ program, and it’s being added to source control. I don’t want that.
In Windows, executables have the file extension .exe
and I can write *.exe
in the .gitignore
. But in Ubuntu, executables don’t need an extension. How do I make Git ignore that?
2
Answers
The
.gitignore
file does not need to use wildcards. It can match whole names as well. If your executable is named "myprog", then add a line containingmyprog
to the ignore-file.Usually, you would have your build generate its outputs to a subdirectory: e.g.
bin
, and you can put that entire directory into the ignore-file as follows:Add just the name of the file in the
.gitignore
file.But if the file is already tracked by git you will have in all likelihood to untrack it with:
Otherwise you will see that the file is not ignored. Because the
.gitignore
rules work only on untracked file.