Setting Up Git to Ignore ELF Binaries (C/C++ Output on Linux)
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:
$ ls
Makefile print print.c print.h print.o
And we initialize a new git repository in that directory:
$ git init
Initialized 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
# Ignore
bindir
bin/
# or
*/bin/*
Let’s see how we did:
$ git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
Makefile
print.c
print.h
nothing 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.