When we start a new project, we best create a Git repository right away. The only problem when we do that from the command line is that we do not get a .gitignore file. Without such a file, Git will track all files in our repository – including *.exe, *.dll, *.pdp and many more that we do not want. We could go and find a .gitignore from a different project. But there is a better way for our .Net projects:
<!--more-->##IgnoreVisualStudiotemporaryfiles,buildresults,and##filesgeneratedbypopularVisualStudioadd-ons.####Getlatestfrom`dotnetnewgitignore`#dotenvfiles.env#User-specificfiles*.rsuser*.suo*.user*.userosscache*.sln.docstates#User-specificfiles(MonoDevelop/XamarinStudio)*.userprefs#Monoautogeneratedfilesmono_crash.*#Buildresults[Dd]ebug/[Dd]ebugPublic/[Rr]elease/[Rr]eleases/x64/x86/[Ww][Ii][Nn]32/[Aa][Rr][Mm]/[Aa][Rr][Mm]64/bld/[Bb]in/[Oo]bj/[Ll]og/[Ll]ogs/#VisualStudio2015/2017cache/optionsdirectory.vs/#Uncommentifyouhavetasksthatcreatetheproject'sstaticfilesinwwwroot#wwwroot/#VisualStudio2017autogeneratedfilesGenerated\Files/#MSTesttestResults[Tt]est[Rr]esult*/[Bb]uild[Ll]og.*#NUnit*.VisualState.xmlTestResult.xmlnunit-*.xml#BuildResultsofanATLProject[Dd]ebugPS/[Rr]eleasePS/dlldata.c#BenchmarkResultsBenchmarkDotNet.Artifacts/#.NETproject.lock.jsonproject.fragment.lock.jsonartifacts/#Tye.tye/#ASP.NETScaffoldingScaffoldingReadMe.txt#StyleCopStyleCopReport.xml#FilesbuiltbyVisualStudio*_i.c*_p.c*_h.h*.ilk*.meta*.obj*.iobj*.pch*.pdb*.ipdb*.pgc*.pgd*.rsp*.sbr*.tlb*.tli*.tlh*.tmp*.tmp_proj*_wpftmp.csproj*.log*.tlog*.vspscc*.vssscc.builds*.pidb*.svclog*.scc#ChutzpahTestfiles_Chutzpah*#VisualC++cachefilesipch/*.aps*.ncb*.opendb*.opensdf*.sdf*.cachefile*.VC.db*.VC.VC.opendb#VisualStudioprofiler*.psess*.vsp*.vspx*.sap#VisualStudioTraceFiles*.e2e#TFS2012LocalWorkspace$tf/#GuidanceAutomationToolkit*.gpState#ReSharperisa.NETcodingadd-in_ReSharper*/*.[Rr]e[Ss]harper*.DotSettings.user#TeamCityisabuildadd-in_TeamCity*#DotCoverisaCodeCoverageTool*.dotCover#AxoCoverisaCodeCoverageTool.axoCover/*!.axoCover/settings.json# Coverlet is a free, cross platform Code Coverage Toolcoverage*.jsoncoverage*.xmlcoverage*.info# Visual Studio code coverage results*.coverage*.coveragexml# NCrunch_NCrunch_*.*crunch*.local.xmlnCrunchTemp_*# MightyMoose*.mm.*AutoTest.Net/# Web workbench (sass).sass-cache/# Installshield output folder[Ee]xpress/# DocProject is a documentation generator add-inDocProject/buildhelp/DocProject/Help/*.HxTDocProject/Help/*.HxCDocProject/Help/*.hhcDocProject/Help/*.hhkDocProject/Help/*.hhpDocProject/Help/Html2DocProject/Help/html# Click-Once directorypublish/# Publish Web Output*.[Pp]ublish.xml*.azurePubxml# Note: Comment the next line if you want to checkin your web deploy settings,# but database connection strings (with potential passwords) will be unencrypted*.pubxml*.publishproj# Microsoft Azure Web App publish settings. Comment the next line if you want to# checkin your Azure Web App publish settings, but sensitive information contained# in these scripts will be unencryptedPublishScripts/# NuGet Packages*.nupkg# NuGet Symbol Packages*.snupkg# The packages folder can be ignored because of Package Restore**/[Pp]ackages/*# except build/, which is used as an MSBuild target.!**/[Pp]ackages/build/#Uncommentifnecessaryhowevergenerallyitwillberegeneratedwhenneeded#!**/[Pp]ackages/repositories.config#NuGetv3'sproject.jsonfilesproducesmoreignorablefiles*.nuget.props*.nuget.targets#MicrosoftAzureBuildOutputcsx/*.build.csdef#MicrosoftAzureEmulatorecf/rcf/#WindowsStoreapppackagedirectoriesandfilesAppPackages/BundleArtifacts/Package.StoreAssociation.xml_pkginfo.txt*.appx*.appxbundle*.appxupload#VisualStudiocachefiles#filesendingin.cachecanbeignored*.[Cc]ache#butkeeptrackofdirectoriesendingin.cache!?*.[Cc]ache/#OthersClientBin/~$**~*.dbmdl*.dbproj.schemaview*.jfm*.pfx*.publishsettingsorleans.codegen.cs#Includingstrongnamefilescanpresentasecurityrisk#(https://github.com/github/gitignore/pull/2483#issue-259490424)#*.snk#Sincetherearemultipleworkflows,uncommentnextlinetoignorebower_components#(https://github.com/github/gitignore/pull/1529#issuecomment-104372622)#bower_components/#RIA/SilverlightprojectsGenerated_Code/#Backup&reportfilesfromconvertinganoldprojectfile#toanewerVisualStudioversion.Backupfilesarenotneeded,#becausewehavegit;-)_UpgradeReport_Files/Backup*/UpgradeLog*.XMLUpgradeLog*.htmServiceFabricBackup/*.rptproj.bak#SQLServerfiles*.mdf*.ldf*.ndf#BusinessIntelligenceprojects*.rdl.data*.bim.layout*.bim_*.settings*.rptproj.rsuser*-[Bb]ackup.rdl*-[Bb]ackup([0-9]).rdl*-[Bb]ackup([0-9][0-9]).rdl#MicrosoftFakesFakesAssemblies/#GhostDocpluginsettingfile*.GhostDoc.xml#Node.jsToolsforVisualStudio.ntvs_analysis.datnode_modules/#VisualStudio6buildlog*.plg#VisualStudio6workspaceoptionsfile*.opt#VisualStudio6auto-generatedworkspacefile(containswhichfileswereopenetc.)*.vbw#VisualStudio6auto-generatedprojectfile(containswhichfileswereopenetc.)*.vbp#VisualStudio6workspaceandprojectfile(workingprojectfilescontainingfilestoincludeinproject)*.dsw*.dsp#VisualStudio6technicalfiles*.ncb*.aps#VisualStudioLightSwitchbuildoutput**/*.HTMLClient/GeneratedArtifacts**/*.DesktopClient/GeneratedArtifacts**/*.DesktopClient/ModelManifest.xml**/*.Server/GeneratedArtifacts**/*.Server/ModelManifest.xml_Pvt_Extensions#Paketdependencymanager.paket/paket.exepaket-files/#FAKE-F#Make.fake/#CodeRushpersonalsettings.cr/personal#PythonToolsforVisualStudio(PTVS)__pycache__/*.pyc#Cake-Uncommentifyouareusingit#tools/**#!tools/packages.config#TabsStudio*.tss#Telerik'sJustMockconfigurationfile*.jmconfig#BizTalkbuildoutput*.btp.cs*.btm.cs*.odx.cs*.xsd.cs#OpenCoverUIanalysisresultsOpenCover/#AzureStreamAnalyticslocalrunoutputASALocalRun/#MSBuildBinaryandStructuredLog*.binlog#NVidiaNsightGPUdebuggerconfigurationfile*.nvuser#MFractors(Xamarinproductivitytool)workingfolder.mfractor/#LocalHistoryforVisualStudio.localhistory/#VisualStudioHistory(VSHistory)files.vshistory/#BeatPulsehealthchecktempdatabasehealthchecksdb#BackupfolderforPackageReferenceConverttoolinVisualStudio2017MigrationBackup/#Ionide(crossplatformF#VSCodetools)workingfolder.ionide/#Fody-auto-generatedXMLschemaFodyWeavers.xsd#VSCodefilesforthoseworkingonmultipletools.vscode/*!.vscode/settings.json!.vscode/tasks.json!.vscode/launch.json!.vscode/extensions.json*.code-workspace#LocalHistoryforVisualStudioCode.history/#WindowsInstallerfilesfrombuildoutputs*.cab*.msi*.msix*.msm*.msp#JetBrainsRider*.sln.iml.idea####VisualstudioforMac###globsMakefile.in*.userprefs*.usertasksconfig.makeconfig.statusaclocal.m4install-shautom4te.cache/*.tar.gztarballs/test-results/#Macbundlestuff*.dmg*.app#contentbelowfrom:https://github.com/github/gitignore/blob/master/Global/macOS.gitignore#General.DS_Store.AppleDouble.LSOverride#Iconmustendwithtwo\rIcon#Thumbnails._*#Filesthatmightappearintherootofavolume.DocumentRevisions-V100.fseventsd.Spotlight-V100.TemporaryItems.Trashes.VolumeIcon.icns.com.apple.timemachine.donotpresent#DirectoriespotentiallycreatedonremoteAFPshare.AppleDB.AppleDesktopNetworkTrashFolderTemporaryItems.apdisk#contentbelowfrom:https://github.com/github/gitignore/blob/master/Global/Windows.gitignore#WindowsthumbnailcachefilesThumbs.dbehthumbs.dbehthumbs_vista.db#Dumpfile*.stackdump#Folderconfigfile[Dd]esktop.ini#RecycleBinusedonfileshares$RECYCLE.BIN/#WindowsInstallerfiles*.cab*.msi*.msix*.msm*.msp#Windowsshortcuts*.lnk#Vimtemporaryswapfiles*.swp
That should get rid of all unwanted files and if something is missing, we can add it manually.