Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions prevent_commit_to_main.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#!/bin/sh
#!/usr/bin/env sh
##!"C:\\Program Files\\Git\\usr\\bin\\bash.exe"

branch="$(git rev-parse --abbrev-ref HEAD)"

if [ "$branch" = "main" ]; then
echo "You are on the main branch. Committing to the main branch is not allowed."
exit 1
if [ -z "${GIT_DIR}/MERGE_MODE" ]; then
echo "Merge to main allowed."
exit 0
else
echo "You are on the main branch. Committing to the main branch is not allowed."
exit 1
fi
fi