Quick Tip : Keep App Globals in a separate branch/commit

Spread the love

Open Mobile Version.

While working on a project you might come up with something that you might want to reuse. For example you come up with a date formatter.

Now if your project has some sort of peer review where the changes are going to be merged to the main branch after somebody goes through the changes, then it is a good idea to keep that common/global functionality in a different branch or a commit and never push it along with the current task that you are working on.

Why?

If you have your global functionality in a separate branch it would be easier for you to base off another task from this branch.

Let me explain with an example.

Let’s say while working on updating the Dashboard on an app, I had to create a currency formatting function. Something which you can not only use on the dashboard but also at other places. So you create a new Helpers file and put your code there.

Example:

if (!function_exists('formatCurrency')) {
    function formatCurrency($value)
    {
        $format = '%s$AUD %s';
        $formattedValue = number_format($value < 0 ? $value * -1 : $value, 2, '.', '');
        return sprintf($format, $value < 0 ? '-' : '', $formattedValue);
    }
}

Now consider right after you finish the dashboard task let’s call it D-task, you need to work on the user profile page, say U-task.

Scenario 1

You push your formatCurrency function along with the D-task changes.

You move to U-task and you need to have formatted currency shown there as well, but now you are stuck because unless D-task is reviewed and it’s changes are not available

Scenario 2

You keep your formatCurrency function in a separate branch or a commit.

Now you can base off your U-task branch off the branch that has formatCurrency or cherry-pick that commit on to your branch. Now you can use the common functionality in this branch as well.

This will save you some effort and hassle of managing code conflicts or waiting for your changes to get merged to the main branch.

Leave a Reply

Your email address will not be published.

%d bloggers like this: