0

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?

phd
  • 82,685
  • 13
  • 120
  • 165
  • Generally speaking you should not include your build output files in source-control - so why are you wanting to do this? – Dai Apr 18 '23 at 02:33
  • https://stackoverflow.com/a/19023985/7976758 , https://stackoverflow.com/q/39409461/7976758 Found in https://stackoverflow.com/search?q=%5Bgitignore%5D+without+extension – phd Apr 18 '23 at 09:21

2 Answers2

7

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 containing myprog 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:

bin/
paddy
  • 60,864
  • 6
  • 61
  • 103
1

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:

git rm --cached my-file

Otherwise you will see that the file is not ignored. Because the .gitignore rules work only on untracked file.

Philippe
  • 28,207
  • 6
  • 54
  • 78