Sensible Git Repo Initialization


This mini tutorial is dedicated to my wife, who never remembers to add a .gitattributes file.

How to set up a sensible git repo

  • init the repo with git init
  • add a .gitattributes file which enforces LF line endings for most filetypes
  • add a .gitignore which ignores compiled or temporary files
  • make an initial commit

Sample .gitattributes file

# Handle line endings automatically for files detected as text
# and leave all files detected as binary untouched.
* text=auto eol=lf

# .bat must be crlf to work
*.bat text eol=crlf

Why is .gitattributes important?

Setting up a .gitattributes file like the one above will ensure commited files always have the same line endings, regardless of the user's OS or local git core.autocrlf setting.

Why is .gitignore important?

If your working directory contains any temporary files .gitignore is important to avoid accidentally checking them in.


tagged git tutorial