How to prevent remote branch deletion in git witho

2020-07-24 06:27发布

Is there any way to block deletion of remote branches?

I want to block deletion of remote branches but normal flow like code checking and check out should work fine!!

without using gitolite! is it possible ?

please help !

标签: linux git
3条回答
萌系小妹纸
2楼-- · 2020-07-24 06:37

Yes, it is possible. Just add a suitable server side git hook.

You probably want to use a pre-receive hook. For details have a look at here or here.

Example:

#create repositories
git init a
git init --bare b

#add the hook in "b"
echo -e '#!/usr/bin/bash\nread old new ref\ntest $new != 0000000000000000000000000000000000000000' >>b/hooks/pre-receive
chmod +x b/hooks/pre-receive

#create a commit in "a"
cd a
echo foo >test
git add .
git commit -m testcommit

#push it to "b"
git push ../b master

#try to delete remote branch
git push ../b :master
查看更多
霸刀☆藐视天下
3楼-- · 2020-07-24 06:42

I'm not sure why you're avoiding gitolite (which is sort of the end point of all access control, as it were), but I have a sample pre-receive script here that uses hooks.* git config entries to do some simple access controls. It's not as fancy as gitolite but it does some things I cared about once. :-)

查看更多
叼着烟拽天下
4楼-- · 2020-07-24 06:50
 refs/heads/*,delete)
       # delete branch
              if [ "$allowdeletebranch" != "true" ]; then
                echo "*** Deleting a branch is not allowed in this repository" >&2
                    exit 1
                fi

adding this in update hook solved my problem Hope this will help someone else too

查看更多
登录 后发表回答