Friday, September 30, 2011

gitignore skipping folder hierarchy

I was just trying to setup a new git repository for existing code base. Tree is something like this (names changed but structure retained)

│   ├───bin
│   │   ├───x64
│   │   │   ├───Debug
│   │   │   └───Release
│   │   └───x86
│   │       ├───Debug
│   │       └───Release
│   └───libs
│       ├───Debug
│       └───Release


Now my intention is to setup .gitignore file with following assumptions
1) libs at root and files below should be ignored
2) libs below apps and all files below should be considered for tracking
3) Debug and Release folders under apps\bin\x86|x64 should be ignored
4) Debug and Release folders under apps\libs should be considered for tracking

Help file of git ignore doesn't provide much help about placeholders and skip tokens. Though I wish a regex option could be ideal. After some hit and trial I could come up with following .gitignore file


With this when I add and check for status I get desired result.

$git add .

$git status
# On branch master
# Initial commit
# Changes to be committed:
#   (use "git rm --cached ..." to unstage)
#       new file:   .gitignore
#       new file:   apps/apps1.txt
#       new file:   apps/libs/Debug/appslibsdebug.txt
#       new file:   apps/libs/Release/appslibsrelease.txt
#       new file:   apps/libs/appslibs1.txt