简体   繁体   English

我们是否应该将所有本地git分支推送到远程仓库上?

[英]Should we push all local git branches on the remote repo?

I am working on a project & try to follow git-flow. 我正在做一个项目,并尝试遵循git-flow。 Hence, I branch out quite often on my local machine. 因此,我经常在本地计算机上分支。 When I'm done, I would merge these branches into the develop branch and then delete the local branches. 完成后,我会将这些分支合并到develop分支中,然后删除本地分支。 This happen for most bug fixes and small features. 大多数错误修复和小的功能都会发生这种情况。 I do push important branches. 我确实推动重要分支。

This is because I don't want to keep too many remote branch on my Github repo. 这是因为我不想在Github存储库中保留太多的远程分支。

Is this an acceptable practice? 这是可以接受的做法吗? I realize that by doing this, I might make it hard to find commits of a merged branch, since I no longer have a label pointing to it 我意识到这样做会导致很难找到合并分支的提交,因为我不再有指向它的标签了

Hope to hear your opinion. 希望听到您的意见。 Thanks 谢谢

No, you don't push a local branch to a central repo, unless it is actually needed as branch for someone else to see (ie for shared work). 不,您不会将本地分支推送到中央存储库,除非实际上需要将其作为其他人看到的分支(例如,共享工作)。 And if you did for whatever reason, you delete the branch once it was fully merged. 并且,如果出于任何原因执行了此操作,则在完全合并分支后将其删除。

Git branches serve as heads and you use them for that. Git分支充当头,您可以使用它们。 After merge the history will plainly show what branch was there, so keeping it would be redundant. 合并后,历史记录将清楚地显示那里的分支,因此保留该分支将是多余的。 And if you want to continue the branch, it can simply be re-created at the last commit. 而且,如果您想继续分支,可以在最后一次提交时重新创建它。 IOW deleting/not pushing it loses no info whatsoever. IOW删除/不推送它不会丢失任何信息。

You should read this article about git best practices 您应该阅读有关git最佳做法的本文

Regarding, your question: Handle obsolete branches so they can be referenced if needed, without cluttering up the git branch listing: 关于您的问题:处理过时的分支,以便在需要时可以引用它们,而不会弄乱git分支列表:

git merge -s ours obsolete-branch

This will merge obsolete-branch into the current branch, but completely discarding the changes in the obsolete branch. 这将把过时的分支合并到当前分支中,但是会完全丢弃过时的分支中的更改。 I usually make it clear in the commit message for the merge that the branch is being discarded instead of a true merge. 我通常会在提交的合并消息中明确指出分支将被丢弃,而不是真正的合并。

git merge -s ours --edit obsolete-branch

If the old changes are ever needed for reference or to be resurrected, it's as easy as checking out the last commit on the merged branch and creating a new branch pointing to it. 如果以前的更改需要参考或要重新使用,则只需检查合并分支上的最后一次提交并创建指向它的新分支即可。

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

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