1

I know this question is asked many times on SO.

I just wanted to get proper way of branching and fixing mine.

My working methodology on Git branching is:

  1. Checkout to master
  2. Take pull of all branches one by one on master ( if there are any latest branches that are not merged on master yet but existed on remote ) Checkout new branch from master.
  3. Work on that branch
  4. Push to Git
  5. Now again checkout to master
  6. And take pull again
  7. And then checkout to new branch again.
  8. All above.

So, I know this is not the right way to doing this Git branching.

I always stumbled myself on these branching and sometime I lost work too due to wrong branching and push pull.

Can anybody explain the write way of doing this branching properly? Including best practices as well. So, I will follow those procedures for my current project.

Also, my main concern is having latest code all the time on any branch ( I think master as we checkout new branch from that branch )

1 Answers1

1

I'll try to explain one way to work with branches. You can find other in the internet and from my point of view there is not a perfect one.

enter image description here

In this image, you have your master branch. The one that has the working code that is on production.

From Master branch, you have a develop branch. This branch will have your most recent code, with features that your testing and building.

From Develop branch, you have all your feature branches. The ones that you'll start new features

So, the workflow would be: "Oh, I have an idea off feature to add to this project."

  • Create a branch from develop with the name of 'feature idea'
  • Develop the feature in that branch
  • Merge to develop to test
  • "Oh, another idea!"
  • Create another branch from develop named 'ideia 2'
  • Develop in that branch
  • Merge to develop
  • test test test
  • Merge to master

This way you'll always have a working code at master and a 'beta' version at develop

Leonardo Cavazzani
  • 293
  • 1
  • 2
  • 13
  • Thanks for in-depth response Leonardo. I will definitely keep in mind for future. Strangely no one else replied so far but you helped me a lo. –  Jan 04 '19 at 16:38
  • I like that. But, how does "Release" fit into the flow? – Dennis Jul 13 '20 at 15:54