6 ms·
Show HN: Why you should not use feature branches
- maushu 7y agoSomeone forgot about continuously merging master to feature branch to keep the merge simple.
- rejschaap 7y agoIf everyone is working in a feature branch and only bug fixes are done in master, then most of the merges will be simple. However, when a feature is done and merged to master, all the feature branches need to merge the work and that merge will be disproportionately difficult. kennethh posted a link that explains this well: https://martinfowler.com/bliki/FeatureBranch.html https://martinfowler.com/bliki/FeatureBranch.html
- AstralStorm 7y agoYou cannot avoid this, only can parcel the cost and accept more breakage on the way. With a big merge, others have time to inspect and know of breaking changes. with million tiny merges (or working on trunk, same) you either freeze change due to risk of breakage or end up with broken master regularly.
- rurban 7y agoOnly if you don't know rerere, and don't use it immediately after updating master. I carry tons of feature branches with me, which are automatically rebased. Only once or twice a year I need to fixup things a bit, and those things are the things I immediately worked on, so I know for sure how to merge it. Everything is scripted. If you let them stall it becomes a mess, sure. If do it properly it's trivial.
- aequitas 7y agoPlease don't merge continuously, rebase instead. You have to handle the conflict one way or the other. But at least rebasing doesn't give you an incomprehensible git history filled with spaghetti and extraneous merge commits.
- ulisesrmzroche 7y agoYou can always squash the branch before merging back to master.
- rglullis 7y ago- "Show HN" when there is nothing really to show - Submitted by the author of the post - Author of the post is founder of company - Provocative, click-baity Headline We are better than that, HN.
- jpdel 7y agoNot sure how the title is provocative? Even less click baity. And is there a rule I am not aware of against submitting my own posts?
- gus_massa 7y agoSubmitting your own stuff is OK here. You can add some comment explaining that you are willing to answer questions, but it is optional. Anyway, most people here will assume that the owner will read the comments sooner or later. (Reposting and reposting and reposting your stuff is not OK.) Anyway, this is an article that is on-topic, but it is not a good ShowHN. From https://news.ycombinator.com/showhn.html https://news.ycombinator.com/showhn.html > Blog posts, sign-up pages, and fundraisers can't be tried out, so they can't be Show HNs. (Disclaimer: I prefer rebasing.)
- jpdel 7y agoOk thanks. Won't post articles as Show HN in the future.
- tjwds 7y ago"Your feature branch is your own perfect garden and you can keep it clean and shiny. But it is separated from the other gardens of your team. The more you work apart, the harder it is to reconcile." But then, later in the article, "It is 2019. If you don’t have a continuous integration setup that builds and runs tests automatically … then set it up yesterday. If you break anything you’ll be notified before it becomes a problem for the whole team." Which, in my experience, greatly helps to mitigate the "it works on my machine" factor that arises from having a new branch for each task. I appreciate the perspective, but I've found working with feature branches much better than trunk-based development. I'll take my merge conflicts any day. :-)
- kennethh 7y agoIf one read Martin Fowler about feature branching, https://martinfowler.com/bliki/FeatureBranch.html https://martinfowler.com/bliki/FeatureBranch.html and articles from Jez Humble both agree on that one should use trunk based development and use feature toggles in most cases for development.
- AstralStorm 7y agoSure, do end up with hundreds of commits where any given combination of feature flags fails, except sometimes the default. Seriously, this is the quintessential Gentoo Linux problem. Nobody can test all the combinations making the flags almost instantly useless. (And some essentially forced on.)
- timw4mail 7y agoHaving used Gentoo for a long time I haven't seen it be that big of an issue. But I can definitely see too many feature flags leading to a byzantine web of untestable combinations.
- jpdel 7y agoAgree that feature flags count should not explode because you can never test all combinations. Feature toggles should drive the life span of a feature from start of development to "adopted and becomes the default" or "rejected and we scrap it all out". At the end of the day the number of feature toggles should remain relatively low.
- kaelig 7y agoOne of the issues with feature branches is that long-lived feature branches easily go stale, and each day that passes by makes it riskier to merge them into master. While I agree with the author on the general idea of trunk-based development (and feature switches), can't we get the best of both worlds by allowing short-lived pull requests where code review can happen? I'd be curious to hear from teams here who push directly to master and how this workflow works for them.
- jstimpfle 7y agoNot doing any of this myself, but the keyword here is "rebase". (But yeah, there's a problem with reduced testing during feature development. What if a feature branch breaks the main branch and it does not get noted during feature development? I'd argue if it affects the core then it's not strictly a "feature")
- golergka 7y agoYour git strategy should depends on your business release cycle and priorities. In this case, it's a trade-off between dev branch stability and development speed. With trunk-based development, everyone sees everyone else's work in progress and it's easier to integrate different features together. With feature branches, however, dev is more stable and there's more responsibility on merging to branch back to dev. Are you deploying to public a few times a day like a web service, or are you working towards an early release, like a AAA game? Does your team sit together in one room, collaborating with one another, other do they take completely independent task and do them remotely, working from all across the globe, with the only point of interaction being a pull request once or twice a week? It's impossible to say what's better or what's worse without these priors.
- 11235813213455 7y agoIt's more that feature branches should be rebased instead of merging the main branch into it (like most developers unfortunately do) [pull] rebase = true in your ~/.gitconfig, and just pull the branch your forked from This way, the git history is linear, clean and readable
- AstralStorm 7y agoAnd you lose information about when given code was done. (Commit date and parent) Which is crucial to know if any given piece is stale in a bigger project. Stale code may be rotten code. Why is a linear history better again? If you cannot read history graphs, perhaps you should really not use a VCS where merging happens.
- ScottFree 7y agoRebase is so terrible and not because of the lost commit history (most of which deserves to be lost, imho. git merge history is too verbose and oftentimes not useful). My issue with rebase is that as soon as you want a single other person to commit code to that branch, you can no longer rebase. Everything must be merged from that point on, otherwise the histories diverge and you wind up in rebase/merge hell. The only alternative I've found is to over-communicate every push to your co-worker because it requires him to stash his changes, delete his local branch, pull down the "new" remote branch and re-apply his changes.
- pxue 7y agouse interactive rebase?
- turdnagel 7y agoNot really a show HN. Also, rebase master into your feature branches regularly.
- AstralStorm 7y agoI recommend pulling instead. That way you do not lose information on when given code was done and conflict resolution is visible, making hacks like git-rerere less required and automated merging tools more potent. This is really important when there are parallel feature branches and even more so when features are codependent. E.g. if feature a depends on feature b, if you rebase feature a you cannot just pull it into feature b as there will be duplicate commits. If you want nice lines you should hire a painter. If you want easy merges, merge instead of rebasing.
- seren 7y agoWe are using features branch that we are rebasing on master. This allow to have code reviews before something is actually in master (something you might or might not want depending on your worflow or criticity of the sw you are working on) Rebasing (and squashing) allow to keep a linear and clean history. Rebasing and squashing also have downsides, you lose the finer day to day commits, in exchange of ideal history, but at least it should be mentioned in a 2019 post about having too much feature branches in git...
- arnvald 7y agoI've tried trunk-based development before, and while it provides certain benefits, I don't think it's a silver bullet. > Why you should not use feature branches > Keep reading, all the objections you can think of are wrong. The tone of the title and some parts of articles suggests that trunk-based development is objectively better than feature branches. I feel that it's rather a matter of opinion. You might want to try it out, it might work better for you than feature branches. But I don't think saying "feature branches are wrong approach" or "your objections are not valid" is true for everyone. One example are code reviews. > If the code review culture is strong in your team then it can very well be done on the commit to the main branch. Personally I find this inconvenient. Reviewing a single commit does not show me the bigger picture. Let's say I refactor some code before adding a new feature. Refactoring is in a single commit, but to see whether this refactoring makes sense, it's better if the reviewer sees the next step, then they can understand better why I refactored it in this particular way. > The main thing to improve here is probably not the branching model, but the code review process. Maybe this is true. Maybe my way of thinking about code reviews is wrong. However, again, I feel it's a matter of preference. I tried both ways and I certainly prefer reviewing the whole feature than single commits. One more problem I find with trunk-based development: it happened to me before that a developer did something completely wrong. They misunderstood the requirement, they misunderstood the code - it happens, the world's not perfect. With feature branch I'll just ask developer to start from scratch. `git branch -D` and that code is gone. With trunk-based development the code is already in the master branch, and while it obviously can be changed or reverted, it's already there, people already have pulled this code, they modify this code, they look at it and try to understand it, they try to figure out why it's there. Again, I'm not saying here that trunk-based development is a bad idea. It might be working for you, it might not, everyone's different. I believe the article explains the benefits of trunk-based development pretty well, I wish though it wasn't presented as an objectively superior alternative to feature branches.
- jpdel 7y agoFair enough. You have a valid point on "your objections are not valid" is not the right tone. I'll edit to highlight that feature branches have their benefits in some cases. Thanks for reading!
- jph 7y agoA "feature branch" means something much different to my teams. A feature branch for us is a short-life topic branch, and typically for one use case, kanban card, etc. We use short-life topic branches for each feature, each bug fix, each infrastructure-as-code change, each documentation update, etc. We prefer short-life topic branches vs. committing to the `master` branch (or equivalent `develop` branch) because of multiple reasons: 1. A topic branch gives good code isolation for distributed development: I can share a topic branch with you, directly, without needing to merge to master. 2. A topic branch makes it really easy to do many kinds of popular git workflows; this includes many popular CI servers, git automation scripts, git aliases, etc. 3. A topic branch is great for integrating early and often into code reviews, and also with master. For example, we use a feature branch that uses feature toggles, and we can do CI/CD to propose changes to master as often as we want, and we can rebase the topic branch as often as we want. We can choose whether a repo will prefer merge, or rebase, or rebase with preserve, and between elided linear history or real graph history. 4. We favor automatic integration, meaning when we push a topic branch, and the reviews are all good, and the tests are all green, then the CI/CD does an automatic integration process, including an automatic deploy. When the topic is integrated, then the topic branch is deletable. 5. Finally, I've tried the "TBD just merge to master" approach with multiple teams, and inevitably it turns out to be significantly harder and more complex to coordinate, especially at speed, scale, and with more stakeholders. If you're interested in git, you can see some of the git alias topic branch commands that we use: https://github.com/GitAlias/gitalias/blob/master/gitalias.txt https://github.com/GitAlias/gitalias/blob/master/gitalias.tx...
- atsjie 7y agoThis. All teams I've worked for in the last few years basically did this. Although we never distinguished between features/topics explicitly, the proces would be the same. Having one branch per story is just very simple from a management perspective; it aligns user requirements, graphics design, development, code review and deployment into one trackable unit. Stories are never too large so in practice code branches don't exist for too long, a couple of days usually. If two or more developers work on the same story they'll use the same branch. If two stories are code-wise interdependent they'll reuse each other's branches as they see fit.
- jstimpfle 7y agoI guess the main advantage of feature branches is that you can easily drop them if it turns out the feature was a bad idea or too hard to implement. The advantage of trunk based development would be that the feature gets potentially more testing. Same goes for interactions with the main line code - if feature development breaks the core in subtle ways, it will be noticed earlier using trunk based development.
- AstralStorm 7y agoIt will be noticed - by angry users. Which is why untested continuous deployment is madness. When you do checkpoint regular releases done often, you get a chance to smoketest and block a release. Automated smoke tests only go so far in fixing this - if you could cheaply, reliably and completely fully automate testing, everyone would already do that. About the only way to do continuous deployment is to not deploy into production but use lagged deployment practice...
- jstimpfle 7y agoYes - in my case the "users" are just my colleagues (and yes, they could get angry, but the feedback can be worth it). I believe that "trunk" is not commonly meant to be immediately deployed to users. But, maybe things are different in the web world, where "deploy" is as easy as "upload to server"?
- mikekchar 7y agoI like TBD -- a lot. However there are a couple of problems with it. If your team is not collocated in a time zone then you'll one one guy (me, for instance) who will push 8 hours of development into trunk without anyone else getting a chance to look at it. The same thing happens if you have someone who just "disappears" for a day or two and effectively has a feature branch. You need to have discipline on your team to push often (I like to push at least every 20 minutes). I also tend to think that continuous deployment with TBD is risky. It depends on how good your automated acceptance tests are, but I tend to like to do a manual sanity check before deployment. It's a lot easier when you are not working on a moving target. Finally, sometimes you just have to break something in order to change its direction. This forces you into a feature branch if you are doing continuous deployment. We've occasionally experimented with having an "integration branch" that acts like trunk but isn't deployed. You can then time your trunk deployments, potentially cherry picking from the integration branch. It seems like a good solution, but I've found it to be more trouble than its worth most of the time. Having said all that, my preference would be to abandon continuous deployment and instead have regular deployment (say once a week or once every 2 weeks) with a mechanism for hot patches. Then force everyone to work mostly core hours and have continuous integration (with commits coming in every 5 minutes or so). In my experience this has produced dramatically better results than feature branches. However... On my team it is impossible (not least because I'm 9 time zones away from the majority of my team mates). So feature branches are an acceptable second best.
- jstimpfle 7y ago> (I like to push at least every 20 minutes) That sounds extreme to me. What kind of development do you do that makes this possible? I rarely finish something within 20 minutes. Often, I'm thinking about the right way to do something for a day or longer before I decide to push some results. (UPDATE, before I even start to write some code!)
- mikekchar 7y agoIntermediate results are fine as long as the tests are passing. If you push, then your teammates will see what you are doing and one of them can give you advice if they think you are going in a disadvantageous direction. If you hold the code out for a whole day, there is no way for anyone else to know what you are doing (unless you interrupt them to tell them, or they somehow know to ask you). On a well functioning TBD team with true CI, everybody knows what everybody else is doing because they are constantly looking at diffs when they pull trunk. But yes, it is extreme ;-) It's one of the 12 XP practices (continuous integration). Interestingly, the original idea behind CI servers was that when you push to trunk, you were never sure if there would be an integration problem. So if someone pulled trunk, they might get garbage. So the CI server was there so that you could get a visual indication of whether or not it was safe to pull trunk. And if it went red the whole team would instantly take a look to see what happened. It's a team based approach rather than an individual approach.
- dwyer 7y agoI just rebase my feature branches before merging. Keeps the tree more or less linear.