Should I Create One Branch per Task or One Branch for the Entire User Story

62 Views Asked by At

I'm uncertain if this is the appropriate forum for my post, but if it isn't, I'm willing to relocate it to another platform. (If so, Could you please advise me on where it might be more suitable?)

I have a user story in Jira that I'm eager to tackle. To facilitate my work, I've broken down the user story into individual tasks.

For instance, the user story entails building a page with a table, sortable columns, pagination, and a filter dropdown. My approach involved breaking down each of these features into separate tasks and creating branches for each task.

However, I've noticed that each task or branch depends on the preceding one. This observation has led me to question whether it would be more advantageous to create a single branch for the entire user story.

Are there any benefits to creating branches for each task?

2

There are 2 best solutions below

0
tutumantutu On

Creating a separate branch for each ticket will be beneficial if you will have other people working with you on the project. It will also make testing and code reviews easier. However if you are working on this project alone, you can create a feature branch, then do the related work within this feature branch.

0
Guildenstern On

It’s impossible to answer this question in an objective and pithy way which also isn’t unintentionally misleading.

This is a workflow problem. Workflow problems can’t be resolved by giving a bullet list of supposedly best practices. They need to be discovered in a dialectical manner, by way of practice and reflection.

You can’t say:

  1. Make one branch per task
  2. Make one branch per Jira issue (assuming a Jira issue might have multiple tasks)
  3. Don’t use branches at all!

Because these points don’t tease out the “why”—they inevitably either become rote (in the mindless sense) practices and/or limiting boxes.

The process can unfold like this:

  • John: Why do I need branches at all?
  • Lars: Because we’re all working against the same GitHub repository. We need to have separate branches for the pull requests.
  • John: Makes sense. But actually I am using my own fork. Why can’t I just use main [the main branch] on that? And then make a PR where my:main -> upstream:main?
  • Lars: Sure. You can do that. But what if you are working on three different issues at the same time?
  • John: I’m pretty sure I can handle three issues at the same time without needing branches.
  • Lars: Okay fine.
  • John: By the way, I noticed that you use one branch per Jira task? And you divide your Jira issues into like five sub-tasks each…! A bit overkill, no?
  • Lars: I don’t think so. They’re all named after the issue and the task. It’s my way of subdividing all the work.
  • John: But how do you keep the branches up to date? Keep in mind that we all have to use git-rebase to keep our feature branches up to date now! Sounds like a problem for your five-branch setup…
  • Lars: Yeah well no worries. I have a new enough git(1) so I can just use git rebase --update-refs—takes care to update all my five branches!
  • John: Okay okay, fair enough!
  • Lars: …
  • John: Personally though before I was doing this “branchless” thing I just did one issue per Jira issue. The Jira issue was part of the branch name and the commits that had to do with some subtask would mention it in the commit message. Then later I would get back to some subtask or something, maybe—I would just amend that subtask commit. Or I would add another subtask commit. The subject line mentions the subtask so I can group them easily. I feel that having multiple branches would just confuse me!
  • Lars: Sure, I can see that.