Protect deleting/renaming file in git repository

181 Views Asked by At

Is it possible to have one or more files in a git repository that can be changed but not deleted or renamed? The use case is about a repository setup where multiple env files can only be tweaked by developers but prevent them to accidentally delete or rename the files as the CI would break without them with that exact name.

One idea I had was to write some sort of bash or node script and hook it in a pre-commit git hook with husky, but I am not sure how would that script would look like yet. Another idea was to initially set the right file permissions on the env files but I am not sure those would be retained in a git repository cloned on different OS platforms.

Anyway maybe there are some more idiomatic and smart ways to do this. Quite surprisingly I could not find anything online... So all sorts of creative solutions are accepted if not too cumbersome. thanks!

0

There are 0 best solutions below