How To

Git Attributes: Control Your Vendor Folders

A simple way to hide your vendor folders from everyone on Git and Github.

When you’re developing code, a lot of the time you have vendor or bower_component folders that you don’t need. That is, you don’t need them for the code, but you do for the development.

A year ago I explained how I handle my vendor folders. Essentially, I use SVN to ignore things so they don’t get uploaded to WordPress. And that’s great but

What about Git?

Enter Git Attributes Enter Git Attributes

The .gitattributes file lets you define attributes for paths. What that means is you can assign an attribute to a file which will then impact how various Git operations occur.

Operations are things like checking your code out or pushing a release (something familiar to Githubbers). Basically an operation is when Git does a ‘thing.’ Whatever that thing will be. And the Attributes file allows you to specify what happens to specific files (or folders) when that thing happens.

Top ↑

How Do You Use It? How Do You Use It?

There’s a lot more to it than this, but if your goal is to exclude vendor folders and .git files from your zips to send them off to people, then you’ll want to have your .gitattributes file look like this:

/vendor/ export-ignore
.gitattributes export-ignore  
.gitignore export-ignore

This results in when you use GitHub and tell someone to download the zip from it, it will exclude those files.

Top ↑

What Else Can I Do With It? What Else Can I Do With It?

Have a problem with line endings because one person on your dev team uses Windows? gitattributes can help.

Need to make a change like that for everyone on a system? Or maybe you want to make sure you never include those vendor and documentation folders? The Pro Git Book says this:

Attributes for all users on a system should be placed in the $(prefix)/etc/gitattributes file.

Before you ask, unless you changed it, $(prefix) is nothing for pretty much everyone. You may have a /usr/local/git/etc/ location though.