53

I recently started working with GitFlow model as implemented by bitbucket. And there is one thing that is not completely clear to me.

We try to regularly address our technical debt by backlogging, planning, and implementing the refactoring tasks. Such refactoring branches end with pull-requests that are merged in develop. My question is where do the refactoring branches belong in GitFlow?

  • Using feature prefix seems the most logical, however it does not feel entirely right, because refactoring does not add any new functionality.
  • However using bugfix prefix seems not right as well as there is no actual bug refactoring fixes.
  • Creating a custom prefix on the other hand seems like complicating if not over-engineering the things.

Did you have such situation? Which practice do you use to address this? Please explain why.

AMA
  • 632
  • 1
  • 5
  • 8

3 Answers3

70

Refactoring work should go in a feature branch.

The prefix "feature" is just a word to describe a discrete programming task, you could choose any word you like, any branch from development is either a "feature" branch or a "release" branch

Adding a new prefix such as "refactoring" is problematic. As you will often do some refactoring when adding a feature, you are simply giving yourself a naming problem and adding confusion. ie. "some of our feature branches are called 'refactoring', no they don't contain all the refactoring work and sometimes they have bug fixes or features in them'

similarly "hotfix" branches are not called hotfix because they contain hotfixes, but because they branch from master rather than develop

Ewan
  • 83,178
1

I'd say it depends on following cases:

  1. If maintaining the main branch, the correct place is hotfix/.
  2. If maintaining the release/ branch, the correct place is bugfix/.
  3. The best case scenario (and if possible) is to maintain refactoring candidates in the feature/ branch right away.

Keep in mind that the options 1. and 2. are real world scenarios and covered by the git flow strategy because of meeting release deadlines or saving costs (or better gaining profit in time or money). So I don't see any troubles in organizing that way since git flow updates main, develop and feature/ branches in order.

Comment: If you have never expirienced case 1 or 2 so far this might change if development goes on.

EDIT: 2025-01-21 10:45 Since I'm still convinced with my answer a further approach came into my mind. Why not refactoring the release-branch if there shall be a unique rule? According to the well known picture of nvie.com the release branch might be an accepted candidate for refactorings since it's also a place for bugfixes. The refactoring changes are going to develop and main branch which meets all criterias. Source: https://nvie.com/img/git-model@2x.png

Daniel
  • 19
  • 2
0

Sorry for Necro - but wanted to share that I have learned that minimizing "branch depth" is something that is integrated behavior introduced from programming logistics (reducing nesting/depth generally improves everything).

To answer this question specifically: /refactor exists across all branch structures.

In the case of Repository tracking this made things difficult - until accepting that there SHOULD be hanging feature branches, acting as default tags! This allow you to append individual work-item branches from these features. This behavior prevents your local working changes from becoming an overwhelming hodge-podge belonging to many branches; which makes everything else complicated - as you will have to deal with merge conflicts, stash/apply, or cherry-pick nightmare.

TLDR: Don't be afraid of branch-depth! This help narrow down changes to specific intents. If you are having trouble with branch-cycling, your concept of branch design is likely hurting you.