How to disable Github branch protection rule for certain/auto-generated files

Viewed 446

I have a git repository where some of the configuration files are auto-generated by scripts and pushed to the main branch. I like to enable branch protection rule to protect the main branch but like to disable these rules for certain file patterns.

Whether this is possible in Github?

1 Answers

While it is not possible, you could isolate those auto-generated script in their own folder.

And that folder could be a submodule (as illustrated here), referencing your own repository, but following a different branch, one which is not push-protected.

git submodule add -b scripts -- /url/to/your/own/repo scripts
git commit -m "Add script branch as submodule folder"

From the main branch, a git submodule update --remote would pull the latest of the scripts branch into the scripts subfolder.

Related