Reputation: 6341
We need to prevent pushing to some branch on our bitbucket repo.
And we think that it will be ok for us to prevent it locally.
Is there any way to prevent pushing to some branch locally via some pre-push hook?
OS: Windows.
Upvotes: 2
Views: 3454
Reputation: 20148
This is obviously a suboptimal solution, but since BitBucket doesn't provide a possibility to add an update hook I will provide it anyway.
To prevent pushing to a branch via a local hook you can use the pre-push
hook (available since git 1.8.2).
#!/bin/sh
while read local_ref local_sha remote_ref remote_sha
do
if [ "$remote_ref" = "refs/heads/test" ]; then
echo "Pushing to branch \"test\" is forbidden"
exit 1
fi
done
exit 0
Just replace test
with the corresponding branch name you want to protect from pushs.
For more information on the pre-push hook you can take a look at the example file, and if you want to learn more about hooks in general you can read the corresponding chapter in the gitpro book.
IMPORTANT
Remember that you have to install this hook in every clone of the repository, since it's a client side hook rather than a server side one.
Obviously a server side update
hook would be preferable.
Upvotes: 7