Skip to content

Instantly share code, notes, and snippets.

@Nunocky
Last active June 22, 2025 23:11
Show Gist options
  • Save Nunocky/eeb9129adf8c6e275fe037f2dc479d1d to your computer and use it in GitHub Desktop.
Save Nunocky/eeb9129adf8c6e275fe037f2dc479d1d to your computer and use it in GitHub Desktop.
main, developへの merge, rebaseの禁止
#!/bin/sh
protected_branches="main develop"
current_branch=$(git symbolic-ref --short HEAD)
for branch in $protected_branches; do
if [ "$current_branch" = "$branch" ]; then
echo "❌ ERROR: You cannot commit directly to '$branch' branch!"
exit 1
fi
done
exit 0
#!/bin/bash
protected_branches="main develop"
branch=$(git rev-parse --abbrev-ref HEAD)
# Check if current branch is in protected_branches
for protected_branch in $protected_branches; do
if [ "$branch" = "$protected_branch" ]; then
echo "❌ ERROR: You cannot perform a merge on '$branch'!"
exit 1
fi
done
#!/bin/sh
protected_branches="main develop"
while read local_ref local_sha remote_ref remote_sha
do
for branch in $protected_branches; do
if echo "$remote_ref" | grep -Eq "refs/heads/$branch$"; then
echo "❌ ERROR: Pushing to '$branch' branch is not allowed!"
exit 1
fi
done
done
exit 0
#!/bin/sh
protected_branches="main develop"
current_branch=$(git symbolic-ref --short HEAD)
for branch in $protected_branches; do
if [ "$current_branch" = "$branch" ]; then
echo "❌ ERROR: Rebase is not allowed on '$branch' branch!"
exit 1
fi
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment