DEV Community

Cover image for Create a gitignore file with dotnet cli
Emanuele Bartolesi
Emanuele Bartolesi

Posted on

Create a gitignore file with dotnet cli

When I create a new project on GitHub, the first thing that I add in the initial repository is the .gitignore file (often for VisualStudio) and then I copy that file from another solution on my pc and I commit it.

Image description

But time to time, I add some files that I don't want on my repo.
Since a while, I found the perfect solution: create the .gitignore files with the dotnet cli.

Create the .gitignore with the dotnet cli

Not many people know that the dotnet cli provides a command to create a .gitignore file, practically perfect.

In the root folder of your project, you can launch the command below from your favorite terminal application or from the terminal inside Visual Studio or Visual Studio Code.



dotnet new gitignore


Enter fullscreen mode Exit fullscreen mode

This command will create a perfect .gitignore in your folder with a lot of settings to ignore unnecessary files, not only for Visual Studio but also for Visual Studio Code and JetBrains products.

You can find the latest version of the file at the official repository.

GitHub logo github / gitignore

A collection of useful .gitignore templates

A collection of .gitignore templates

This is GitHub’s collection of .gitignore file templates We use this list to populate the .gitignore template choosers available in the GitHub.com interface when creating new repositories and files.

For more information about how .gitignore files work, and how to use them the following resources are a great place to start:

Folder structure

We support a collection of templates, organized in this way:

  • The root folder contains templates in common use, to help people get started with popular programming languages and technologies. These define a meaningful set of rules to help get started, and ensure you are not committing unimportant files into your repository.
  • Global contains templates for various editors, tools and operating systems that can be used in different situations. It is…

Top comments (0)