Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it wise to use branching with one-man git project?

Tags:

I have a small project on git, on which I am the sole developer. For now, I used only one main branch to actually get it working.

Now the project is somehow working and I would like to just implement some new features. The question is, should I create new branch for each new feature and merging it back afterwards?

The fact is, my workflow will be just improving the "feature branch" and merging it back into the unchanged "master branch" most of the time anyway, so does it make sense to make new branches at all?

like image 465
Karel Bílek Avatar asked Nov 15 '09 19:11

Karel Bílek


People also ask

When should I use branches in Git?

In Git, branches are a part of your everyday development process. Git branches are effectively a pointer to a snapshot of your changes. When you want to add a new feature or fix a bug—no matter how big or how small—you spawn a new branch to encapsulate your changes.

Which one is best branching Git workflow to follow?

The GitHub flow branching strategy is a relatively simple workflow that allows smaller teams, or web applications/products that don't require supporting multiple versions, to expedite their work. In GitHub flow, the main branch contains your production-ready code.

What is the most popular branching strategy in git?

One well-known branching strategy is called Git Flow. The main branch always reflects the current production state. There is a second long-running branch, typically called develop. All feature branches start from here and will be merged into develop.


3 Answers

From the gitworkflows man page:

Any nontrivial feature will require several patches to implement, and may get extra bugfixes or improvements during its lifetime.

Committing everything directly on the integration branches leads to many problems: Bad commits cannot be undone, so they must be reverted one by one, which creates confusing histories and further error potential when you forget to revert part of a group of changes. Working in parallel mixes up the changes, creating further confusion.

Use of "topic branches" solves these problems.

You should use topic branches (aka feature branches) even if you are the sole developer.

In addition to the reasons cited above, I would add:

  • If you have a feature that will take a long time to complete, working on a feature branch allows you to easily suspend work on that feature to work on something else.
  • If there is a chance that you need to support multiple versions of your code (i.e. your current version is v2.0, but a customer/user is using v1.0 then using topic branches allows you to easily merge bug fixes into multiple versions.
like image 161
Tim Henigan Avatar answered Sep 24 '22 04:09

Tim Henigan


should I create new branch for each new feature and merging it back afterwards?

Yes, because halfway through implementing that feature, you'll find a show-stopping bug in your production code, and you will be thankful that you can git checkout master back to the code that is in production and fix it. My rule is to always have my master branch in a deployable state.

like image 37
Ben Avatar answered Sep 26 '22 04:09

Ben


I would say yes, for me every time I push code into the production environment I will create a version branch. So if something goes wrong I can simply go back to that branch and make the fix push the fix out and then merge my code change back into the trunk.

like image 33
Anthony Avatar answered Sep 26 '22 04:09

Anthony