DEV Community

Cover image for Prompt Confirmation When Pushing Directly to Master
Kenta Takeuchi
Kenta Takeuchi

Posted on • Originally published at bmf-tech.com

Prompt Confirmation When Pushing Directly to Master

This article was originally published on bmf-tech.com.

Overview

How to create a safety net to prevent direct pushes to the master branch in git. Although it would be ideal to prohibit pushes to the master branch on GitHub, due to DevOps constraints, there were issues with GitHub settings, so we opted to use hooks for configuration.

Introduction

Since we want to set this globally, create a pre-push file under ~/.git_template/hooks. If the .git_template directory does not exist, create it.

Note that even if you set it globally, it will not be reflected in existing repositories. If you want to apply it to existing repositories, you need to prepare a pre-push under ./git/hooks in the existing repository and write the same source there.

Refer to Prompt Confirmation When Pushing to Master Branch with git pre-push Hook for what to write in pre-push.

It might be safer to only allow 'yes' as the answer.

Grant execution permissions to the newly created pre-push
chmod +x pre-push

Setup is now complete.

References

Top comments (0)