如何在git上限制对master分支的访问 [英] How to restrict access to master branch on git

查看:886
本文介绍了如何在git上限制对master分支的访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




  • 管理员

  • HTML / UI开发人员



我不希望给予 master 分支给我的HTML开发人员,因为他们不需要使用它,也不应该滥用核心代码。



尽管他们需要在自己的分支上工作 UI-开发。 PS:我使用BitBucket

解决方案

Git本身并没有这样的功能,但许多托管服务提供者都这样做。这通常被称为分支保护。据我所知,无法阻止读取访问。



使用BitBucket



BitBucket允许很多为防止通过分支保护而采取的行动的自定义。为了保护分支机构:


  1. 转到项目中的存储库。

  2. 点击添加权限。


  3. p>在分支字段中,选择分支名称,分支模式或分支模型。


    $ b

    • 分支名称 - 选择一个现有的

    • 分支模式 - 使用分支模式语法指定分支以匹配分支名称。


    • 分支模型 - 选择分支类型来限制访问。

    • 选择类型您希望防止的操作。




      • 分支删除 - 防止分支和标签删除。


      • 重写历史记录 - 防止在指定的分支上进行历史重写 - 例如通过强制推送或rebase。

      • 没有拉取请求的变化 - 防止直接将更改推送到指定的分支;所有修改 - 防止压入指定的分支并限制创建与指定分支匹配的新分支(es) )或模式。

      • 可选:为任何选定的限制添加豁免。将用户或组添加为豁免意味着它不适用于他们。这不是必需的;不添加任何豁免意味着限制将适用于每个人。


      • 点击创建完成。

      • >

        来源


        $ b $ h1>使用GitHub

        GitHub中的受保护分支:




        • 无法强制推送


        • 无法删除


        • 直到所需的状态检查通过才能将合并到它们中的更改




        保护分支:


        1. 在GitHub上,导航到存储库的主页。

        2. b $ b
        3. 在您的存储库名称下,单击设置。

        4. 在左侧菜单中,单击分支。 >
        5. 在受保护的分支下,使用下拉菜单选择要标记为保护的分支。

        6. 选择保护这个分支。
        7. Cli ck保存更改。


        来源



        使用GitLab



        在GitLab ,保护分支会执行以下操作:


        • 它阻止创建它,除非用户拥有主许可权>
        • 它可以防止除了拥有Master权限的用户之外的所有用户推送它

        • 它可以防止任何人强行推送到分支机构

        • 阻止任何人删除分行



        保护分行:


        1. 导航到项目的主页面。


        2. 在右上角,点击设置轮并选择受保护的分支。

        3. 在分支下拉菜单中,选择您要保护的分支,然后单击保护。


        4. 完成后,受保护的分支将出现i n已被保护列表。

        5. 然后,您可以通过检查开发人员可以合并或开发者可以推送
          $ b 来源


          I have a single repo in which I have 2 user groups:

          • Admins
          • HTML/UI Developers

          I do not wish to give read/write access of my master branch to my HTML developers as they do not need to work on it and should not be misusing the core code.

          Though they need to work on their own branch ui-developers. How do I do this on git?

          P.S.: I am using BitBucket

          解决方案

          Git itself does not have such feature, but many hosting providers do. This is generally known as branch protection. There is no way to prevent read access as far as I know.

          Using BitBucket

          BitBucket allows a lot of customization for the actions to prevent by branch protection. To protect a branch:

          1. Go to a repository in a project.

          2. Choose Settings > Branch permissions.

          3. Click Add permission.

          4. In the Branches field, select either Branch name, Branch pattern, or Branching model.

            • Branch name - select an existing branch by name.

            • Branch pattern - specify a branch using branch pattern syntax for matching branch names.

            • Branching model - select the branch type to restrict access to.

          5. Select the type of actions you want to prevent.

            • Branch deletion - prevents branch and tag deletion.

            • Rewriting history - prevents history rewrites on the specified branch(es) - for example by a force push or rebase.

            • Changes without a pull request - prevents pushing changes directly to the specified branch(es); changes are allowed only with a pull request.

            • All modifications - prevents pushes to the specified branch(es) and restricts creating new branches matching the specified branch(es) or pattern.

          6. Optional: Add exemptions for any of the selected restrictions. Adding a user or group as an exemption means that it will not apply to them. This is not required; not adding any exemptions means the restriction will apply to everyone.

          7. Click Create to finish.

          Source

          Using GitHub

          Protected branch in GitHub:

          • Can't be force pushed

          • Can't be deleted

          • Can't have changes merged into them until required status checks pass

          To protect a branch:

          1. On GitHub, navigate to the main page of the repository.

          2. Under your repository name, click Settings.

          3. In the left menu, click Branches.

          4. Under Protected Branches, select the branch you want to mark protected using the drop-down menu.

          5. Select Protect this branch.

          6. Click Save changes.

          Source

          Using GitLab

          In GitLab, protecting a branch does the following:

          • it prevents its creation, if not already created, from everybody except users with Master permission
          • it prevents pushes from everybody except users with Master permission
          • it prevents anyone from force pushing to the branch
          • it prevents anyone from deleting the branch

          To protect the branch:

          1. Navigate to the main page of the project.

          2. In the upper right corner, click the settings wheel and select Protected branches.

          3. From the Branch dropdown menu, select the branch you want to protect and click Protect.

          4. Once done, the protected branch will appear in the "Already protected" list.

          You can then allow some access to users with developer rights by checking "Developers can merge" or "Developers can push"

          Source

          这篇关于如何在git上限制对master分支的访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆