Setting Up Git to Ignore ELF Binaries (C/C++ Output on Linux)
Gregg
The starting point for this experiment was from here
An Example using C Program Source
Let’s say we have a pre-existing directory of some C source code files:
$ lsMakefile print print.c print.h print.o
And we initialize a new git repository in that directory:
$ git initInitialized empty Git repository in /home/user/tmp/printer/.git/$ cat .gitignore# Ignore all*# Unignore all with extensions!*.*# Unignore all dirs!*/# Unignore make files!Makefile# Ignore .o files*.o# Ignorebindirbin/# or*/bin/*
Let’s see how we did:
$ git statusOn branch masterNo commits yetUntracked files:(use "git add <file>..." to include in what will be committed).gitignoreMakefileprint.cprint.hnothing added to commit but untracked files present (use "git add" to track)
So the print and the print.o files are not showing up, which was our initial goal.
You may have to tweak the settings in the above .gitignore file to your own situation, but as you can see it is possible to setup git to ignore the ELF binaries output by gcc. I would probably also add a.out to the list of unignored files just to cover those times when you’re not using a Makefile. YMMV.