Prompt Confirmation When Pushing Directly to Master

Published: (March 15, 2026 at 06:16 AM EDT)
1 min read
Source: Dev.to

Source: Dev.to

Cover image for 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: Even if you set it globally, it will not be reflected in existing repositories. To apply it to existing repositories, place a pre-push script under ./git/hooks in each repository and copy the same source there.

Refer to Prompt Confirmation When Pushing to Master Branch with git pre‑push Hook for the contents of the pre-push script. It might be safer to only allow yes as the answer.

Grant execution permissions to the newly created pre-push script:

chmod +x pre-push

Setup is now complete.

References

0 views
Back to Blog

Related posts

Read more »

Travigo

Travel as fast as you speak with Gemini! Where live agents meet immersive storytelling & 3D navigation. This project was created for entering the Gemini Live Ag...

Micro games

Hey Gamers! 👾 As part of the Rapid Games Prototyping module, we are tasked with reviewing a peer's game. The challenge is to analyse a prototype built in just...