I\'d like to only track certain directories in git in a larger project, where most directories will be excluded and only a few will be tracked. So, I wanted to use
Don't mention the directories in your .gitignore, just the files. Doing this and explicitly adding the directories you want to track should give you what you want:
$ cat > .gitignore << EOF * !bar EOF $ git add -f iwantthesefiles
This will let git track bar and everything in the directory iwanthesefiles.