Select Page

Introduction

Creating git branches for a project’s repo is not uncommon at all among git users. In fact, for development work, most people using git tend to create branches for bug fixes and other small sets of changes they’d like to commit to the project. 

However, is it actually that necessary at all? Let’s find out!


Advantages of using git branches

Not everyone would want the same opinion, after all. So before we even start to give you the reasons why you should consider removing git branches, it’d be a good idea to tell you why people really like to use git branches so much, and so often.

Prevents code mess

This is perhaps the most promising aspect of the Git Branching feature. Examples work better than explanations, and that’s exactly what I’ll do to tell you why it’s cool.

Take for example that you are working on a project code project called ‘HW’. You’ve been working hard for quite a long time on the project to print out the string ‘Hello, World!’ as an output (like for more than 10 mins). What you’d like to do now is to change ‘Hello’ to ‘Bye’, but are worried that you could end up ruining the entire program in the process.

This is where Branching comes into play. What you can do is instead of making the changes directly in the master branch, you can create a new development branch and change only the parts of code you’d like to change. Once done, you can later do what’s called Merging to mix the new changes and apply them to your master branch. 

This ensures that the rest of your code stays the same and untouched in the master branch, and in case you mess something up even after merging the changes, you have the option to revert back to a previous state of your repository by using a reset command.

But wait a second. If you could essentially revert back to a previous state when something goes wrong, why use git branches then? Exactly. If your primary use for branches is to avoid code corruption, then you could essentially consider not using them. Hang on till we discuss this point later on in the article. 

Individualism

Nifty word right there. What I’m really trying to say is that git branching allows many developers to work on their own particular features at the same time, while the main code base stays intact. I’d say this is actually more reasonable than using branches primarily for bug fixing and small tweaks, as there are no negative or unnecessary aspects. As compared, if many people work on their own features on the same branch, there could possibly be countless situations where things don’t go along. 

However, if you’re the only person working on your project, you’d probably not consider this to be a valid reason for you to use git branches.

There’s actually way more good sides to using git branches, which I don’t know of (let me know in the comments if you have any particular reasoning). But I do think there is still some unnecessariness to using git branches, at least in half the cases if not in every.


Why you should delete git branches

Removes Clutter

Projects do tend to get larger over time, and the more branches you create for every small addition you make to your main branch, the harder it gets over time to keep track of them all. 

Instead of creating branches for small tweaks, a better practice is to comment out the original code in a file and write out the new changes below them. Once the changes are final, remove the commented lines, or you may even wish to keep them (which I myself tend to do), if you ponder over the possibility of coming back to it later on for a reversion. This, to the very least, ensures that you don’t waste extra time simply just to create more branches, and produce unnecessary clutter. 

Improves performance & saves disk space

If you don’t happen to have the habit of removing branches once they’re merged into the master branch, you’re in big trouble. Not only does it impact the performance of your project folder, but it takes up a huge amount of space too. This is crucial as the other terminal commands that’re applied project-wide, would also be executed slowly due to the larger number of files the commands would have to scan through. 

Not necessary for solo projects

Definitely not, considering that git branching is the heart of collaboration (I really appreciate this fact about branching, not gonna lie). As long as you don’t need to work on multiple features of a program with other developers at the very same time, there’s no need to create extra branches for working on with yourself. Like c’mon! 

Bug fixing with branches is counterproductive

As you had already seen previously, if your primary use case for git branches is to separate bug fixing code so that it doesn’t ruin the whole thing, you need to stop doing that. Why? Because if you ensure to create regular commits on your repository after every major change, you can easily revert back to a previous state of your project before you mess things up trying to kill bugs. 

Hard it sounds? Not at all! As long as you know the git reflog command, can take notes of weird hash codes, and write them out as arguments for the git reset command, you’re good to go.Â