0

I have a file "src/data/sensitive-data.json" that contains contents:

{
  "appInstanceKey": "<Virtual App Key Here>",
  "email": "<Email Here>",
  "password": "<Password Here>"
}

I pushed that to my repo.

I now added to my .gitignore

src/data/sensitive-data.json

and then pushed that to my repo in a separate commit.

I want to now change my sensitive-data.json to actual credentials so i make the change and tell git to stop tracking with SourceTree (i believe it's using git rm -r --cached) and push that.

The problem is when someone new pulls the repo, the data folder and the sensitive-data.json file don't exist at all. I want it to exist with the original contents, but I want to be able to change the data locally without it being tracked.

What step did I mess up or what am I missing to accomplish this? I looked at other SO answers and I feel like i'm following them correctly.

Thank you

user1189352
  • 3,628
  • 12
  • 50
  • 90
  • Does this answer your question? [How to stop tracking and ignore changes to a file in Git?](https://stackoverflow.com/questions/936249/how-to-stop-tracking-and-ignore-changes-to-a-file-in-git) – Jeff Mercado Feb 03 '20 at 20:57
  • @JeffMercado there's ALOT of information on that thread that seems to be misleading.. i'm still trying to sort through it but that's why i created this one – user1189352 Feb 03 '20 at 21:36
  • My understanding is you basically have a file that contains configuration data. By default, you want it to have certain settings, but for your own local development, you want to change the values and not accidentally commit those changes. In this case you could `--assume-unchanged` or `--skip-worktree`. – Jeff Mercado Feb 03 '20 at 21:40
  • @JeffMercado ah i'm currently reading what the difference is between the two right now on that thread.. thank you going to try soon – user1189352 Feb 03 '20 at 21:43
  • the -assume-unchanged worked just fine it looks like. thanks – user1189352 Feb 03 '20 at 21:47
  • 1
    `--skip-worktree` might be the best option. https://stackoverflow.com/a/13631525 – Jeff Mercado Feb 03 '20 at 21:48
  • 1
    Does this answer your question? [GIT - How to remove local file from tracking, but leave copy on remote repository?](https://stackoverflow.com/questions/40410267/git-how-to-remove-local-file-from-tracking-but-leave-copy-on-remote-repositor) – phd Feb 03 '20 at 22:04
  • https://stackoverflow.com/search?q=%5Bgit%5D+add+application+config+ignore+changes – phd Feb 03 '20 at 22:04
  • yes those all helped. reverted to using the --skip-worktree after some more reading and the suggestion – user1189352 Feb 03 '20 at 22:36

1 Answers1

2

There is a great article on github about removing sensitive data from repository, but maybe you should consider having structure like this:

/src/data/sensitive-data.json           <-- This is not tracked by git at all
/src/data/sensitive-data.json.example   <-- This is tracked by git

Having structure like that ensures that future code users will know how the file should be looking and it is pretty safe for you to not include sensitive data in your repository.

Magiczne
  • 1,586
  • 2
  • 15
  • 23