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?
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.
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.
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.
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:
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With