Git: 如何通过访问控制保护git-flow中的develop/master分支(免受新手的影响)?

6
前几天我阅读了https://www.atlassian.com/git/tutorials/comparing-workflows/forking-workflow,现在有一个问题。
如果在项目中使用功能分支或Gitflow分支工作流:是否有选项可以将用户推送的功能分支作为跟踪功能分支到origin,并发出拉取请求,只有项目维护者才能将跟踪功能分支合并到主分支(功能分支工作流)或develop(Gitlow分支工作流)?
换句话说:是否可以将分支分配给用户,这样如果不想过度复杂化事物但仍然需要保证代码审查,就不需要立即使用Forking Workflow,从而保护主/develop分支免受新手的影响?

1
您IP地址为143.198.54.68,由于运营成本限制,当前对于免费用户的使用频率限制为每个IP每72小时10次对话,如需解除限制,请点击左下角设置图标按钮(手机用户先点击左上角菜单按钮)。 - KurzedMetal
1个回答

0

像github、bitbucket、gitlab、vsts等远程git服务,都有“保护”分支的能力,以防止直接推送或删除分支。如果你想在本地模拟这样的功能,可以使用git钩子:https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks

例如,防止提交到主分支的示例:https://gist.github.com/aaronhoffman/ffbfd36928f9336be2436cffe39feaec

pre-commit文件:

#!/bin/sh
# prevent commit to local master branch

branch=`git symbolic-ref HEAD`
if [ "$branch" = "refs/heads/master" ]; then
    echo "pre-commit hook: Can not commit to the local master branch."
    exit 1
fi

exit 0

预推送文件:

#!/bin/sh
# Prevent push to remote master branch

while read local_ref local_sha remote_ref remote_sha
do
    if [ "$remote_ref" = "refs/heads/master" ]; then
        echo "pre-push hook: Can not push to remote master branch."
        exit 1
    fi
done

exit 0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接