0

I have a file named secret that I want to first fill in with a non-secret stub, commit, and then add it to .gitignore for posterity. However, once git addd, it's tracked and ignores .gitignore. So I tried git rm --cached. Works for me, but now it's removed from the upstream repo. Any way t do this?

Irina Rapoport
  • 1,404
  • 1
  • 20
  • 37
  • That's not how git works on my PC: I can perfectly well put a file .gitignore that I've added before, so that changes are ignored afterwards. – Marcus Müller Oct 07 '22 at 15:51
  • 3
    What you should do to keep it simple in this case is add a _sample_ file that you track.... and ignore the _real_ one. People create their real file from the sample one and then they can change it and git won't care. – eftshift0 Oct 07 '22 at 16:01
  • The amount of details included in your question is insufficient for troubleshooting. Please include how you are adding your file to the `.gitignore` and where you have placed this `.gitignore` file in your project. Also, the path to the file is needed to see if there are any discrepancies – blurfus Oct 07 '22 at 16:01
  • 2
    You can also ask git to ignore a file that is already tracked with `git update-index --assume-unchanged`, by the way... but it has to be run on a _per repo_ basis (so everybody will have to run it on their repos when they clone (or on their preexisting local repos) to work). – eftshift0 Oct 07 '22 at 16:02
  • @eftshift0 That's not practical. – Irina Rapoport Oct 07 '22 at 16:10
  • @eftshift0 I've seen it done, but it's kind of annoying. I was hoping there is a better way. – Irina Rapoport Oct 07 '22 at 17:16
  • 1
    a pretty common way is to commit a `secret.template` file, and to gitignore `secret`. Then let everyone copy `secret.template` to `secret` and edit that file with their values. – LeGEC Oct 07 '22 at 17:41
  • Yes @LeGEC I've seen it, but I didn't know whether it's for historic reasons for example. Okay. – Irina Rapoport Oct 07 '22 at 17:51
  • @MarcusMüller Really? AFAIK it shouldn't work that way, unless you did something along the lines of [this question](https://stackoverflow.com/q/1274057/184546). – TTT Oct 07 '22 at 21:30

0 Answers0