Skip to main content

Visio and Word files misbehaving with GitHub

All GitHub repositories are initialized with a default .gitattributes file which has the following configuration to handle Microsoft Word files:

*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain

This configuration works fine as long as the Word files in your repositories have only text and tables. The moment you try to commit Word files with images embedded in them or Microsoft Visio files, the line ending conversion and diff applied to them by Git will probably corrupt them. The files will open properly on your computer, but if you try to clone the repository on a different computer and try to open those files you will probably encounter the following messages:
Corrupted Microsoft Word file: The file cannot be opened because there are problems with the contents

Corrupted Microsoft Visio file: An error (100) occurred during the action Open File. Visio cannot open the file because it's not a Visio file or it has become corrupted.
To fix this we need to add/modify the following lines in the .gitattributes files present in that particular repository (if you are using GitHub for Windows, you can do this easily by selecting Options>Settings... for that particular repository):

*.doc binary
*.DOC binary
*.docx binary
*.DOCX binary
*.vsd binary
*.VSD binary

This will tell GitHub to handle the Mircosoft Word files and Mircosoft Visio file as binary files and not apply line ending conversions or diff to them. You should create similar configurations for image files like JPEGs, PNGs and GIFs

More information here: Customizing Git - Git Attributes