简体   繁体   English

合并到master后自动删除git分支

[英]Automatically delete git branch after merge to master

We will be attempting a work flow in github where every ticket is a branch off of master.我们将在 github 中尝试一个工作流程,其中每张票都是 master 的一个分支。
After the ticket is complete, the work is merged into staging where regression and integration tests are performed before it is merged into master.工单完成后,工作将合并到阶段,在阶段中执行回归和集成测试,然后再合并到主阶段。

A team lead brought up the issue of the old ticket branches after a merge will start to build up.一位团队负责人提出了合并后旧票据分支的问题将开始建立。

I found this script and want to know if this would work in our environment.我找到了这个脚本,想知道它是否适用于我们的环境。 We only want to delete branches that have been merged into master.我们只想删除已经合并到 master 的分支。

Github has released a feature where anyone with admin permission to the repository can configure branches to get deleted automatically after pull requests are merged. Github 发布了一项功能,任何对存储库具有管理员权限的人都可以将分支配置为在合并拉取请求后自动删除。 Here are the steps -以下是步骤——

  1. Navigate to main page of the repository and click on Settings.导航到存储库的主页,然后单击设置。
  2. Under "Merge button", you can select or unselect "Automatically delete head branches" option.在“合并按钮”下,您可以选择或取消选择“自动删除头分支”选项。

This feature has been released by Github on July 31, 2019.功能已于 2019 年 7 月 31 日由 Github 发布。

There's no ready-to-use script for your use case as far as I know.据我所知,您的用例没有现成的脚本。 You'll have to create your own tools for that.您必须为此创建自己的工具。

There is a tool called git-flow by Vincent Driessen which was built to assist developers following his git workflow described in "A successful Git branching model" . Vincent Driessen 有一个名为git-flow的工具,该工具旨在帮助开发人员遵循“成功的 Git 分支模型”中描述的 git 工作流程。

It's is not as easy as just deleting the branch after merge because you never know if you'll run into a merge conflict or not.这并不像在合并后删除分支那么容易,因为您永远不知道是否会遇到合并冲突。

Add either of the following to your .gitconfig file for an easy alias to merge and delete a branch with 1 command.将以下任一内容添加到您的.gitconfig文件中,以便使用 1 个命令轻松合并和删除分支。

Alias as a function:别名作为函数:

[alias]
  ff = "!f() { git merge $1; git branch -d $1; }; f"

Alias as a new shell command:别名作为新的 shell 命令:

[alias]
  ff = !sh -c 'git merge $1 && git branch -d $1' --

They both do the exact same thing, just 2 different methods of doing it.他们都做完全相同的事情,只是两种不同的方法。

There is an option in Github UI where repository administrator can configure. Github UI 中有一个选项,存储库管理员可以在其中进行配置。

Under "Merge button", select or unselect Automatically delete head branches.在“合并按钮”下,选择或取消选择自动删除头分支。

https://docs.github.com/en/free-pro-team@latest/github/administering-a-repository/managing-the-automatic-deletion-of-branches https://docs.github.com/en/free-pro-team@latest/github/administering-a-repository/managing-the-automatic-deletion-of-branches

As far as I know, the best option currently is a GitHub app called delete-merged-branch .据我所知,目前最好的选择是一个名为delete-merged-branch的 GitHub 应用程序。 It can be easily integrated into a selected repository as an existing app installation, but its source code is also available .它可以作为现有应用程序安装轻松集成到选定的存储库中,但它的源代码也可用 This app will automatically delete branches after they have been merged through a PR.此应用程序将在通过 PR 合并后自动删除分支。

After pull requests are merged, you can have head branches deleted automatically in GitHub :合并拉取请求后,您可以在 GitHub 中自动删除头分支:

repository -> settings -> (general) pull requests -> check Automatically delete head branches存储库 -> 设置 -> (一般)拉取请求 -> 检查Automatically delete head branches

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM