Home > Blockchain >  Git ignore implementation in C#
Git ignore implementation in C#

Time:11-11

How can I properly implement the use of git ignore to not commit .json files to my repository?

I tried watching a youtube video for help, but after following his tips my json file is still being uploaded.

CodePudding user response:

If you want to ignore you must place the .gitignore at top-level directory of your .git repository.

Here is a link to github which upkeep the .gitignore for C#. Of course you can edit it as you like but the most common things are already done for you.

The general way of updating .gitignore is simple. Add *.anyextension to ignore any file that is with that extension. This can get a lot more complex if you want to ignore more complex things from that file but like I said most of them are done for you already.

E.G

MyGitRepoFoder -> (contents) .git(hidden) you want to place the .gitignore here

Use this its what I use for every C# project, I have also added to ignore anything with JSON extension

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# Visual Studio (>=2015) project-specific, machine local files
.vs/

# User-specific files
*.suo
*.user
*.sln.docstates
*.userprefs

# ignore Xamarin.Android Resource.Designer.cs files
**/*.Droid/**/[Rr]esource.[Dd]esigner.cs
**/*.Android/**/[Rr]esource.[Dd]esigner.cs
**/Android/**/[Rr]esource.[Dd]esigner.cs
**/Droid/**/[Rr]esource.[Dd]esigner.cs

# Xamarin Components
Components/

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
x64/
build/
bld/
[Bb]in/
[Oo]bj/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

#NUNIT
*.VisualState.xml
TestResult.xml

# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c

*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc

# Chutzpah Test files
_Chutzpah*

# Visual C   cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile

# Visual Studio profiler
*.psess
*.vsp
*.vspx

# TFS 2012 Local Workspace
$tf/

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user

# JustCode is a .NET coding addin-in
.JustCode

# TeamCity is a build add-in
_TeamCity*

# DotCover is a Code Coverage Tool
*.dotCover

# NCrunch
*.ncrunch*
_NCrunch_*
.*crunch*.local.xml

# MightyMoose
*.mm.*
AutoTest.Net/

# Web workbench (sass)
.sass-cache/

# Installshield output folder
[Ee]xpress/

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish/

# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml

# NuGet Packages Directory
packages/
*.nuget.targets
*.lock.json
*.nuget.props

## TODO: If the tool you use requires repositories.config uncomment the next line
#!packages/repositories.config

# Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets
# This line needs to be after the ignore of the build folder (and the packages folder if the line above has been uncommented)
!packages/build/

# Windows Azure Build Output
csx/
*.build.csdef

# Windows Store app package directory
AppPackages/

# Others
sql/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.pfx
*.publishsettings
node_modules/
.DS_Store
*.bak

# RIA/Silverlight projects
Generated_Code/

# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm

# SQL Server files
*.mdf
*.ldf

# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings

# Microsoft Fakes
FakesAssemblies/

.vscode/settings.json

#Ignore APK
*.apk

#Ignore JSON
*.json

CodePudding user response:

In order to ignore all files of a certain type, use a wildcard (*) followed by the file extension.

The following will ignore all JSON files within your project

*.json

Sidenote: your .gitignore needs to be located in the top-level directory. In other words, same directory as the solution file is located.

CodePudding user response:

I assume that updating of .gitignore is not enough in your case. You need to stop tracking json files. Point is, that once file has being tracked by git, and then you ignore it - anyway git does not remove it. Because it stops tracking changes of that file, but not file itself.

So, first add *.json to .gitignore.

And then stop tracking any json files, which have been already added to git previously (file is file name for the command below):

git rm --cached <file>

CodePudding user response:

https://github.com/github/gitignore/blob/main/VisualStudio.gitignore Here is a general .gitignore file. Use this in your main directory containing the solution, and it should work.

  •  Tags:  
  • git
  • Related