git 分支权限

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13248246/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 14:53:24  来源:igfitidea点击:

git branch permissions

gitbranch

提问by MikeyJ

Is it possible to set branch permissions using git bash? I would like to have much more strict permissions on the master branch, so that some people can use the development branch and commit to it and may not change the master branch themselves.

是否可以使用 git bash 设置分支权限?我想对 master 分支有更严格的权限,以便一些人可以使用 development 分支并提交给它,而可能不会自己更改 master 分支。

If it is possible how would I go about trying to do it?

如果有可能,我将如何尝试去做?

采纳答案by Trudbert

Git does not have branch specific permissions. You can either make the whole repository read onlyto the people or create one private and one public repository and only push the development branch to the public on while keeping the master only in your private repository.

Git 没有特定于分支的权限。您可以将整个存储库设置为仅供人们阅读,也可以创建一个私有存储库和一个公共存储库,然后仅将开发分支推向公众,而将主存储库仅保留在您的私有存储库中。

Edit:For branch specific permissions, you need a server-side authorization layer like Gitolite— obviously, this requires you to be managing your own Git server.

编辑:对于特定于分支的权限,您需要像Gitolite这样的服务器端授权层——显然,这需要您管理自己的 Git 服务器。

回答by Shyam Habarakada

A typical scenario where this might be needed is to restrict access to official (or release) branches to a subset of people on a team. A good strategy here might be to have two repos -- a primary repo that is more tightly access controlled, and another repo that everybody in the team has access to and is used to setup working branches. And perform pull from the working branches to the main repo, as needed. Of course, you can tweak this to fit your team structure and needs.

可能需要这样做的典型场景是将官方(或发布)分支的访问权限限制为团队中的一部分人员。这里的一个好策略可能是拥有两个存储库——一个受更严格访问控制的主存储库,以及另一个团队中的每个人都可以访问并用于设置工作分支的存储库。并根据需要执行从工作分支到主存储库的拉取。当然,您可以调整它以适应您的团队结构和需求。

This can work especially well with services like github.

这对于像 github 这样的服务特别有效。

回答by sudip

bitbucket supports branch restriction. See the link here : https://blog.bitbucket.org/2013/09/16/take-control-with-branch-restrictions/

bitbucket 支持分支限制。请参阅此处的链接:https: //blog.bitbucket.org/2013/09/16/take-control-with-branch-restrictions/

回答by Sparkler

If your developers team is a civilized bunch who only need a friendly reminder, you can reject a push using a pre-receive server-side hook:

如果你的开发团队是一群文明的人,只需要一个友好的提醒,你可以使用pre-receive 服务器端钩子拒绝推送:

#!/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

Although users can easily fake their git email address, I would still make the hook file itself read only.

尽管用户可以轻松伪造他们的 git 电子邮件地址,但我仍然会将钩子文件本身设为只读。

Refs:

参考:

  1. How can I get push user information in server side git hook?
  2. Writing a git post-receive hook to deal with a specific branch
  1. 如何在服务器端 git hook 中获取推送用户信息?
  2. 编写一个 git post-receive 钩子来处理特定的分支