Wednesday, December 30, 2009

Ignoring files in a GIT repository

To ignore a file:

if the project is /work/project
you have /work/project/.git folder
If you want to have the files ignored over all pages, create a file called:
/work/project/.gitignore and put one line for each file, relative to /work/project, eg:
I have a /work/project/src/cache folder which I want to have its contents ignored (any files within the /work/project/src/cache folder, so I put in .gitignore:

then make sure there are none of these files in the cache folder already:
git rm --cached src/cache/*

Then, the standard commit - note, you may need to directly add .gitignore:
git add .gitignore
git commit
git push projecthostnamehere branchnamehere

For the same project, if you want to ignore on just this local copy, edit:

Note, you don't have to add this change, but you do need to rm anything that was there before, as it only ignores it once it is removed (see git rm --cached src/cache/* above)