Restrict some .gitignore patterns to the root of the working tree

This is necessary so files with similar names which are actually
versioned and important aren't matched by these patterns, otherwise
only intended to match build output files.