![Easy to create .gitignore for the dotnet developers (1) Easy to create .gitignore for the dotnet developers (1)](https://i0.wp.com/res.cloudinary.com/practicaldev/image/fetch/s--BCOPY8mY--/c_imagga_scale,f_auto,fl_progressive,h_420,q_auto,w_1000/raw.githubusercontent.com/rafalpienkowski/resources/master/gitignore/git-logo-png-transparent.png)
Rafal Pienkowski
Posted on
#csharp #dotnet #beginners
TL;DR Starting from .Net Core 3.0, you can take advantage of the build in the .Net framework gitignore file template just by typing dotnet new gitignore
in your terminal.
I assume you are familiar with the idea of a gitignore file. In short words, a .gitignore file is a plain text file in which each line contains a pattern for files or directories to be ignored by the git.
I am a dotnet developer. I don't know if you had this problem, but every time I wanted to create a new repository on the git repository, I lacked the build-in .gitignore file. Russ Hammett made me realize that the GitHub platform has prepared a gititnore file. Interestingly it isn't named C#, CSharp, dotnet. Nope, none of those things. It's called VisualStudio. Quite obvious.Once again thanks Russ.
I like to have a tidy repository without /obj/*
and /bin/*
objects, or other IDE specific things included. Storing such files is both messy and could be dangerous. For instance, you could forget to clean from those artifacts your super-secret password.
One of the possible solutions was to copy a .gitignore file from one repository to another. Not a very elegant but effective solution. Another option is to use sites like https://www.gitignore.io/.
Today that has changed. The .Net Core 3.0 SDK gives us a hand. I bet you now dotnet new command. It has a lot of parameters like mvc, webapp, or webapi. Starting from SDK 3.0, there is a new parameter gitignore, which creates a dotnet gitignore file.
dotnet new gitignore
The created file is a good starting point. It contains rules for the most popular IDEs like Visual Studio, Rider, Visual Studio Code, and tools like NCrunch, R#, Visual Studio profiler, or StyleCop. Of course, you can add your own rules to it.
There is still missing documentation on the docs Microsoft site, but you can check it on yourself by typing in your command prompt:
dotnet new
and going through the documentation which is attached there. Here is
I think that the online documentation will be completed soon. Meanwhile, you can take advantage of the build-in gitignore feature, and you don't have to copy the file from other repositories.
P.S. Don't forget about other dotnet cli commands and options.
Cheers!
Top comments (8)
Subscribe
Bhavesh Ramburn
Bhavesh Ramburn
-
Joined
• Feb 1 '22
- Copy link
thanks was just looking for that!
Russ Hammett
Russ Hammett
Dad, programmer, faux-chef, gamer, book reader
-
Location
Westminster, MD
-
Education
BS Computer Studies
-
Work
Software Engineer at Huntington Ingalls Industries (Formerly G2 Inc.)
-
Joined
• Dec 1 '19
- Copy link
Pretty sure there's a visual studio git ignore on that list from github, should get you most of the way there anyway. Cool stuff otherwise, wonder if the cli could even be pulling from github for the file
Rafal Pienkowski
Rafal Pienkowski
I'm focused on developing and expanding my knowledge and skills. Enjoying new challenges. I'm assuming that there are no stupid questions, there are only silly answers.
-
Location
Bydgoszcz
-
Education
Nicolaus Copernicus University
-
Work
Principal Software Engineer at intive
-
Joined
• Dec 1 '19
- Copy link
You're right that there is the VisualStudio gitignore option. I didn't think that someone can name named the gitignore file like IDE's name (not the platform/language) 😉
Russ Hammett
Russ Hammett
Dad, programmer, faux-chef, gamer, book reader
-
Location
Westminster, MD
-
Education
BS Computer Studies
-
Work
Software Engineer at Huntington Ingalls Industries (Formerly G2 Inc.)
-
Joined
• Dec 1 '19
- Copy link
Yeah, it's a bit odd to be sure
kandarpgautam
kandarpgautam
Everything
-
Location
crewl world
-
Work
Keyboard warrior at Anonymous
-
Joined
• Dec 17 '21
- Copy link
It's not odd. but very obvious thing to do. there are different IDEs which creates different files that might not be necessary for the project but for the IDE.
dyagzy
dyagzy
-
Joined
• Feb 14 '21
- Copy link
Wow, thank you for this insightf. I often use the gitignore file for C++ from the github repository whenever I need to create one for my project. Now I have learnt a better way to do it.
An Vo
An Vo
Software Engineer | Learn | Build | Share
-
Location
Ho Chi Minh City
-
Pronouns
He/Him
-
Work
Fullstack Developer at NFQ Asia
-
Joined
• Nov 17 '23
- Copy link
Easy and perfect!
Ibrahim Mohamed Farah
Ibrahim Mohamed Farah
-
Location
Hargeisa,Somalia
-
Joined
• Mar 23 '22
- Copy link
Thanks, its great feature
For further actions, you may consider blocking this person and/or reporting abuse