Application 2019-05-08

Prompt Confirmation When Pushing Directly to Master

How to create a safety net to prevent direct pushes to the master branch in git.

Read in: ja
Prompt Confirmation When Pushing Directly to Master

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

Tags: Git Shell Script
Share: 𝕏 Post Facebook Hatena
✏️ View source / Discuss on GitHub
☕ Support

If you enjoy this blog, consider supporting it. Every bit helps keep it running!


Related Articles