Skip to content

Instantly share code, notes, and snippets.

@nurmuhammadsirat
Last active November 25, 2020 09:00
Show Gist options
  • Save nurmuhammadsirat/9b31562cafac43ef8b5a0d9bc26b1e34 to your computer and use it in GitHub Desktop.
Save nurmuhammadsirat/9b31562cafac43ef8b5a0d9bc26b1e34 to your computer and use it in GitHub Desktop.
Allow push to certain branches only
#!/bin/bash
allowed_branches=(develop branch2 branch3)
is_allowed=0
for i in ${!allowed_branches[@]};
do
branch=${allowed_branches[$i]}
if [[ "$branch" = "$(git rev-parse --abbrev-ref HEAD)" ]]
then
is_allowed=1
fi
done
if [[ "$is_allowed" -ne 1 ]]
then
echo You are only allowed to push to the following branches: ${allowed_branches[@]}
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment