I have a C# MVC .Net Core application I'm building, the connection string is in a file called appsettings.json
so what I want to do is simply exclude this from my git repository. I have added the following line to the git ignore file:
appsettings.json
I have also tried:
**/appsettings.json
But neither seem to work, the change I've made to the appsettings.json
file still appears, am I missing something fundamental here?
It is totally possible and quite easy to encrypt it. We use environment variables to override the values in appsettings. json in production. The environment variables are loaded from Kubernetes constructs called ConfigMaps (for non-sensitive data) and Secrets (for sensitive data).
gitignore should list the names or name-patterns of files that will be found in work-trees when working with your project, but that should not be committed to the project. In other words, it's not OS-specific, it's project-specific.
The appsettings. json file is generally used to store the application configuration settings such as database connection strings, any application scope global variables, and much other information.
This is a common misunderstanding about the way .gitignore works we all met at some point when working with Git: .gitignore will ignore all files that are not being tracked yet; indeed, files that are already being tracked in your Git repository are not ignored by your .gitignore setup.
To fulfil your need, it would be sufficient to untrack the files that you desire to ignore, i.e. in your case the appsettings.json file. As reported in your question's comments, this has been answered already here. Then, your .gitignore setup will work as you would expect.
Adding an entry to your .gitignore
file won't remove any files that have already been added to your repository. You need to remove them manually. For this you can use the rm
command:
git rm --cached project/appsettings.json
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With