Given that you're using the dotnet command, you can generate a .gitignore file with dotnet new gitignore.
dotnet
dotnet new gitignore
It seems to be a "hidden feature" as I don't see it come up when I type dotnet new --help.
dotnet new --help