-1

I have python project with user_data.json

There is it:

{"money": 100, "games": [], "deleted_games": []}

I commited and pushed it. Now I want people could edit it localy but not be able to commit and push them to origin. How can I do this?

If I can't do it, can I unless forbid clone repository(allowing install ZIP)?

I added the file to .gitignore but this didn't work

XMehdi01
  • 5,538
  • 2
  • 10
  • 34
  • In general, you really can't prevent anyone from doing whatever they want in their local repo. You can however, add a hook to prevent them from being able to push changes. Adding a pre-receive hook that ensure no changes are made to that file should suffice. – William Pursell Jul 13 '23 at 12:07
  • https://stackoverflow.com/search?q=%5Bgit%5D+commit+config+file+ignore+changes – phd Jul 13 '23 at 13:25

1 Answers1

0

Rename your user_data.json to user_data.example.json. This version stays in the repository.

Tell users to make a copy of user_data.example.json and rename it to user_data.json for their local use.

Add user_data.json to .gitignore file. This tells git not to track this file.

Now, users can edit their local user_data.json file, but these changes won't be tracked by git, so they can't be committed and pushed to the repository.

As for your second question, it's not possible to prevent people from cloning your public repository. They can either clone it or download it as a ZIP.

jagmitg
  • 4,236
  • 7
  • 25
  • 59
  • 1
    Related to the last point, OP shouldn't care what people do with their own *clone*, as long as they don't have write access to the origin. (GitHub doesn't have file-level access control.) – chepner Jul 13 '23 at 12:33