chore: add pre-push hook to prevent direct pushes to main

swadhinbiswas committed 2 months ago
a8a1cb4
1 parent c674e22
commit a8a1cb4
1 file changed
+17 -0
Showing 1 changed file+17-0
▼.githooks/pre-push
+17-0
1
+#!/usr/bin/env bash
2
+# ==============================================================================
3
+# Git Pre-Push Hook
4
+# Blocks direct pushes to 'main' — all changes must go through Pull Requests.
5
+# ==============================================================================
6
+
7
+CURRENT_BRANCH=$(git symbolic-ref --short HEAD 2>/dev/null || echo "")
8
+
9
+if [ "$CURRENT_BRANCH" = "main" ] || [ "$CURRENT_BRANCH" = "master" ]; then
10
+ printf "\n\033[0;31m[ERROR]\033[0m Direct push to \033[1m%s\033[0m is blocked.\n" "$CURRENT_BRANCH"
11
+ printf "Please create a feature branch and submit a Pull Request:\n\n"
12
+ printf " git checkout -b feature/your-change\n"
13
+ printf " git push origin feature/your-change\n\n"
14
+ exit 1
15
+fi
16
+
17
+exit 0
0
18