Reputation: 218
I'm writing a C++ application that has source files in a source
directory, within which there is a build
directory. The build
directory contains the Makefile
, so when I build the program I do so from the build directory.
I want git
to ignore the build
directory because it doesn't contain source files. However, I do want git to track the Makefile
. What's the best practice for tracking the Makefile
but ignoring the other build files? Should I be using another directory structure?
Thanks!
Upvotes: 3
Views: 510
Reputation: 27028
Ignore rules are just for file git does not already know about, and you can also git add
any file by specifying it's name.
So, just git add the Makefile, and add an ignore rule to ignore build/
You could place a .gitignore
file in build/
with pattern *
Upvotes: 3
Reputation: 1799
You can tell git to not ignore certain files in .gitignore
by prepending !
to a pattern. So you could put a .gitignore
file in your build
directory with content like this:
# Ignore everything in this directory
*
# Except this file and the Makefile
!.gitignore
!Makefile
To give credit where I think credit is due, this is probably where I first learned about these exceptions.
Upvotes: 6