question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Drop a gitignore file as part of project/sln templates

See original GitHub issue

My workflow for creating a new project with dotnet new is generally something like this:

  1. mkdir MyNewProject
  2. cd MyNewProject
  3. dotnet new console
  4. git init
  5. Browse to github.com/github/gitignore
  6. Find VisualStudio.gitignore
  7. Click “Raw”
  8. Copy the content
  9. Edit a new .gitignore file in the repo
  10. Paste
  11. Save

(I only recently realized that I could use dotnet new console -n MyNewProject to collapse steps 1-3)

(And yeah, I could save time with the gitignore stuff, but I am a lazy engineer and want tools to do things for me 😃)

Whereas, when I play with rust and use cargo, my workflow is this:

  1. cargo new MyNewProject

The results are the same, a single project is created in a new directory with a Git repo and an appropriate gitignore file. I think we could simplify the dotnet new experience quite a bit.

I like that the cargo cli has decided to be Git-by-default. I realize that doesn’t work in all environments but I think that the command-line audience very frequently wants a git repository and gitignore file. Cargo also has a --vcs option which allows you to choose git, hg, or none, and a config system that allows you to have a user-level default if you aren’t using git.

This would also have to be conditional on detecting if the newly-expanded template is already in a git repo.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:11
  • Comments:19 (13 by maintainers)

github_iconTop GitHub Comments

2reactions
baronfelcommented, Apr 18, 2022

I don’t think we’d include one automatically - we should lean on the existing .gitignore item template, or allow folks to generate their own.

2reactions
warrenbuckleycommented, Sep 7, 2021

After a bit of hunting and for anyone else interested, the problem is with dotnet pack and nuget it excludes files starting with a . so obviously .gitignore and similar files will not be part of a dotnet new project template.

To fix this I found it by digging around and seeing this mentioned in this comment https://github.com/fable-compiler/fable-templates/issues/44#issuecomment-912616778

Along with finding it here as well https://github.com/dotnet/templating/issues/2350#issuecomment-610431461

You can see there is an option/flag for dotnet pack -NoDefaultExcludes https://docs.microsoft.com/en-us/nuget/reference/cli-reference/cli-ref-pack#options

Also it could be set in a csproj file inside a propertygroup element

<NoDefaultExcludes>true</NoDefaultExcludes>

So if anyone else stumbles across this issue hopefully you now have a solution to get a .gitignore file to show up

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is Gitignore and How to Add it to Your Repo
The .gitignore file is a text file that tells Git which files or folders to ignore in a project. A local .gitignore file...
Read more >
What exactly does GitHub's "create a new project" menu ...
.gitignore is for telling Git which files to ignore for tracking purposes. This function within GitHub is just a quick-start/helper which will ...
Read more >
Ignoring in Git: How To Use .gitignore Files
gitignore file tells Git which files to ignore when committing your project to the GitHub repository. gitignore is located in the root directory ......
Read more >
Add gitignore(s) to Composer-ready project templates
On a new create-project , it appends rules for the files it's scaffolded, and so the .gitignore we present the user with is...
Read more >
Ignore file changes with Git - Azure Repos
Learn how to exclude files from Git version control by using gitignore and exclude files, the git update-index command, and repo management.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found