是否可以使用git bash设置分支权限?我想在主分支上设置更严格的权限,使得一些人可以使用开发分支并提交到它,但不能自行更改主分支。
如果可以的话,我应该如何去尝试做到呢?
一个典型的场景是需要将官方(或发布)分支的访问权限限制在团队的一部分人员之内。在这种情况下,一个好的策略是拥有两个仓库——一个主要的仓库,其访问控制更为严格,和另一个每个团队成员都可以访问和用于设置工作分支的仓库。然后根据需要从工作分支向主仓库执行拉取操作。当然,您可以根据您的团队结构和需求进行相应调整。
使用像github这样的服务尤其有效。
#!/bin/bash
# Extract the user email (%ae) from the last commit (author email)
USER_EMAIL=$(git log -1 --format=format:%ae HEAD)
# Looping through all the pushed branches
while read oldrev newrev refname
do
branch=$(git rev-parse --symbolic --abbrev-ref $refname)
if [ "master" == "$branch" ] && [ "the_integrator@your_company.com" != $USER_EMAIL ]; then
echo "Naughty naughty!"
exit 1 # fail, i.e. reject push
fi
done