This page looks best with JavaScript enabled

How would you exclude all extension-less executable from your repo?

 ·   ·  ☕ 2 min read

In last post, I expressed how we can export a single file from a git repo the its own repo, preserving their commit history. In this post, I will tell how I dealt with extension-less file to ignore them in my repo.

I have recently started learning C++ from Udemy, it’s a free course. I encourage you to take it if you are willing to learn C++. I was following the instructions on Linux. And special thing about working with C or C++ in Linux is that the executable you get has no extensions in it, unlike Windows, which has .exe extension.

It was a challenge for me to keep .cpp source files tracked, yet exclude the executable files. What would have I done? Without extension, I couldn’t do, for example, *.pyc, like I used to do in Python repositories. Keeping the only cpp files in staging area would have cluttered up my git status output every time a new executable was created, isn’t so?

But How

Remember what ! does in a boolean value? Correct, it negates it. The same could be applied in .gitignore’s entries too. Normally what we do in gitignore file is, we write a statement per line to blacklist files or directory we want to exclude from VCS. With regex support that’s even more powerful.

How about this in .gitignore?

*
!*.*
!*/

So what does the above lines do? As most of you might be aware of, * is shorthand for select all in regex terms. So what we are saying is:

  • ignore/blacklist everything
  • DO NOT blacklist any filename with any extension. Basically boils down to do not ignore any file.
  • DO NOT blacklist any directory. The / at last means we are dealing with directory.

Is there Another Option

Another option is to make a directory and move all the executable files there and exclude that directory with .gitignore. But I like this method more. It gives me the freedom to not mv files, again and again, everytime I compile a new file.

Continue Reading


If you liked this post, the subscription form below is for you.

Share on

Santosh Kumar
WRITTEN BY
Santosh Kumar
Santosh is a Software Developer currently working with NuNet as a Full Stack Developer.