125

合并分支后,是否将其从存储库中删除?
但是,这是一个好习惯吗?

我通常会创建很多分支,因为我不想破坏我当前的版本,我希望删除它们以保持秩序。
但是,如果您使用 Assembla 或 GitHub,来自旧分支的合并请求将保存在站点上,因此如果您删除它们,您将收到错误,因为它无法获取它们......

通常如何管理?

4

4 回答 4

94

删除已合并的分支没有问题。所有的提交在历史记录中仍然可用,即使在 GitHub 界面中,它们仍然会显示(参见,例如,这个 PR指的是我已经PR 被接受后删除)。

于 2012-05-26T10:14:39.833 回答
34

I definitely clean up my branches after they've been merged in.

We use GitLab and merge requests at work, so the historical information about branches is stored there; I don't need them cluttering my branch list, and when I look at a coworker's fork, ideally I'd like only to see the branches of their current active development. If I'm trying to look at some code on their branch, I want to be able to look through just a few currently active branches, and not every feature or fix they've ever started work on.

The above applies to BitBucket and GitHub, too.

The only reason you might have for not deleting a branch post-merge is so you know where a given feature ended, but merge commits (and git merge --no-ff if you really want) make that irrelevant.

于 2012-05-26T13:49:58.890 回答
4

只需注意
您的 DELETED 分支的所有超链接 URL 引用,将被BROKEN

例如
如果你branch_feature_x从你的 repo 中删除分支
,这个分支对应的超链接 URL 将会被破坏
https://github.com/username/project/tree/branch_feature_x

于 2019-10-23T04:32:49.753 回答
2

只是为了澄清,从 git 的角度来看,分支只是链接到某个提交。通过删除分支,您不会从 git repo 中删除提交。当然,分离的提交将在一段时间后通过 git 垃圾收集器进行清理。

仅供参考:我们通常通过 bitbucket 接口将分支合并到 master 中。在那里你可以设置delete feature branch after merge标志。

如果你需要处理太旧的分支,你可以看看一些实用程序,例如这个

于 2020-05-29T13:46:48.990 回答