Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protecting sensitive information in Git

Tags:

git

github

Assume I have a project I'm working on that is a blog. In this blog I have a config file with sensitive information in it. When I decide to push this project to Github, I want the config file filled with example data instead of my sensitive data. What is the best, and most widely used, method of achieving this?

like image 285
will Avatar asked Feb 02 '26 20:02

will


2 Answers

Don't put it there in the first place. Check in an example config file with a different name, add the real config file's name to .gitignore, and never check it in.

If you've already done commits with your config file in place, use git filter-branch to make it go away before you push anywhere public.

like image 134
hobbs Avatar answered Feb 05 '26 11:02

hobbs


One possible approach is:

  1. fill the config file with dummy data, commit changes and push to GitHub
  2. configure git to ignore changes in tracked file:

    git update-index --assume-unchanged config-file

  3. fill the config file with sensitive information
like image 42
Jakob Kroeker Avatar answered Feb 05 '26 11:02

Jakob Kroeker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!