gitrefactoringgit-workflow

best way to refactor master when there is an in-progress feature branch?


If your adding a feature inside a git feature branch and part way through you realize your master code should be refactored, what do you do?

Question Background:

Im adding a communication library (I2C), which needs to get the system-clock frequency in order to set its baudrate (comm. freq). When my USART lib needed the system-clock, I had added a function inside the lib to get it. (I was trying to avoid unnecessary dependencies). After working with I2C, I realized that dependencies made sense for both libs.

So I need to add a function to my ClockControl lib and refactor my USART lib. But I don’t want to loose progress on my I2C feature. What is the proper way to do this with git?


Solution

  • You only have two options, really:

    Option 1: Refactor master and rebase your I2C branch on top of it.

    This option is likely to be very painful if the refactoring is complicated, but if it has limited overlap with your I2C work, it might be relatively painless.

    (Whether you refactor master directly or on another "refactor" feature branch, it doesn't make a difference to this question)

    Option 2: Do both the refactoring and the I2C work on the feature branch. Master will get both when you eventually merge.

    This will be easiest, obviously. It's limitations are: