I have some configuration files to commit on GIT with default parameters. Users can pull these files and can modify them on their local copy but they must not commit/push.
How can I achieve a similar result? the file gitignore doesn't fit my need because file must be commit only the first time
Prevent it on the developer side with a pre-commit hook. Note that git commit --no-verify will bypass this safety mechanism. The code below blocks any changes at all to files dir/key1.json and key2.json.
Simply copy command and paste in terminal and it will display list files exclude from git commit, make sure run this command on your project path
Here you need to create a small bash script to prevent the commit into Dev and Master Branch. First we need to get the branch name where commit is getting performed. This can be done by using git rev-parse --abbrev-ref HEAD command and the resultant can be stored in a variable called branch in this case.
Add all sensitive files to .gitignore to make sure git wonʼt track them. Donʼt try to hide the mistake. Other collaborators and you in a month will appreciate the explanation of what happened and what this commit fixes. To avoid a situation like this in the future, here are a few tips on storing sensitive data:
Could you use git's "assume unchanged" function? If this is set, git always assumes that the file in question has not been modified. This means that git status, git commit etc. will skip the file. Please note that the user can still push a new version of the file into your remote repo but it will take some extra work to do that.
Here's a question where the usage of "assume unchanged" was discussed more thoroughly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With