Michael Whelan

behaviour driven blog

gitignore Files

There are a number of files that you don't want to store in your git repository. These could be binary files, such as the packages folder for Visual Studio applications or the node_modules folder for node projects, or automatically generated files such as ReSharper user files or files produced by the build system. If you create a file in your repository named .gitignore, Git uses the file patterns in it to determine which files and directories to ignore when you make a commit. You can also create a global .gitignore file, which is a list of rules for ignoring files in every Git repository on your computer. You can learn more about the file patterns from Pro Git.

Creating a .gitignore file

Creating a .gitignore file is slightly tricky on Windows. When you try to create it in Windows Explorer, it interprets the gitignore part of the file name as the file extension, and so thinks that you are trying to create a file without a name. You get the aptly named "You must type a file name." error message.

windows error

To get around this issue, just create a normal text file, such as gitignore.txt. Open the file in a text editor and add all of your rules. Finally, open a command prompt, navigate to the folder containing the file, and use the ren command to rename it.

ren gitignore.txt .gitignore

.gitignore Templates

The contents of a .gitignore file vary by operating systems, environments, and languages. There are a few useful resources for finding the right combination of rules for your particular project flavour.

gitignore.io website

The gitignore.io website is very handy. It lets you type in any combination of rules from a pre-defined list, and then either generate the .gitignore file in the browser or download the generated .gitignore file to your computer.

gitignore.io

GitHub

When you create a new repository on GitHub you can choose to add a .gitignore file from GitHub's collection of .gitignore file templates.

github

GitHub maintains an official list of recommended .gitignore files for many popular operating systems, environments, and languages, which they use to populate the new repository .gitignore list.

About Michael Whelan

Michael Whelan is a Technical Lead with over 20 years’ experience in building (and testing!) applications on the Microsoft stack. He is passionate about applying agile development practices, such as BDD and continuous delivery, to agile processes. These days his primary focus is ASP.Net MVC Core and Azure. He contributes to a number of open source frameworks through TestStack.

comments powered by Disqus
Google

Google