skip to Main Content

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


  1. 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/
    
    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search