Wednesday, May 30, 2012

Creating a .gitignore file for .NET development

Why a .gitignore file?

By default Git will monitor all the files inside your folders.  So this means that even bin and obj folders and (if you are using Resharper, your _ReSharper files) are listed to be added to your repository. I don’t think you want to include these files inside your source control system(at least I don’t).

Creating the .gitignore file in Windows

I’m not a commandline guru, so I tried creating this file the easy way. I created a new text file inside my repository folder and tried to rename it to .gitignore.  Unfortunately no success:


It seems that Windows doesn’t understand dot files (and Git uses this a lot; .bashrc, .gitignore, etc…). Windows expects your files to have a name.extension convention.

So back to the Gitbash console…  but no .gitignore. Type “touch .gitignore”. This will create the .gitignore file with no content.


Adding the .gitignore content to support .NET development

So now we have our .gitignore file, but it is still empty.  What information should I add? Depending on the kind of development you’re doing(.NET, Java, Ruby), you probably want to add different data. Don’t loose time searching for this data yourself, instead go to and pick the content that suites your needs:


I’m going for the CSharp.gitignore file. Copy the content to your clipboard and open the .gitignore file in your favorite text editor (i.e., notepad, wordpad, notepad++, etc).  Paste the CSharp.gitignore content and you are good to go!


tahsin hasan said...

nice post. u may get .gitignore is not working. see the fix at tahSin's gaRage .

Christian Bright said...

I also need to customize .gitignore file to include some .NET-specified rules to prevent painful conflicts while working as a team so that everyone else can grab it and add to his project controlled by Git.

Prescott Torres said...

It's important to note that the NuGet group applied the 'package restore' function for exactly this issue.

Travis Carpenter said...

Even if you created ".gitignore" you should note things that you can't ignore file which is already being tracked by Git. And one more thing is that empty directories are not tracked by Git.