Git flow question, merging to master and develop
Asked Answered
S

2

7

I am currently using git flow with sourcetree. Work is agreed for the sprint and I create branches off develop to commit code into. I merge the feature branches into develop, then at the end of sprint I merge to master and code goes into production.

This works fine, however, if a fix needs pushing to master or if other work is bought into sprint, commits need to be sorted and cherry picked into master which can get very messy.

This can cause lots of blockers, as work needs to be pushed to master, tested and signed off before other work can be committed into develop.

Is there a way to safely bring in new work and commit to develop?

Stalinist answered 14/4, 2021 at 10:30 Comment(1)
This can cause lots of blockers, as work needs to be pushed to master, tested and signed off before other work can be committed into develop, I don't believe this is true. You can merge your hot-fixes into master while still merging features into develop. After each hot-fix is merged into master then you should also merge master into develop.Integrand
C
13

I merge the feature branches into develop, then at the end of sprint I merge to master and code goes into production.

You can certainly do that if you wish, but typically in Git Flow you don't merge develop directly into master because of the exact problems you are running into:

This can cause lots of blockers, as work needs to be pushed to master, tested and signed off before other work can be committed into develop.

The way Git Flow avoids these problems is with release and hotfix branches. (See diagram for details.)

You simply create a release branch for testing prior to releasing, and therefore work on develop never has to stop. (Note you don't have to create a release branch from the tip of develop; you can use any prior commit that you wish to branch from.)

When you need to do a hotfix into production, you create a hotfix branch off of master.

After your code is merged into master from either release or hotfix branch, then you would also merge master back into develop. (Or you could merge the release and hotfix branches back to develop just prior to merging them into master, but merging master back after is IMHO slightly cleaner and easier to manage.)

Side note: the release and hotfix branches are usually well-defined, however, since you are currently working without them, you still can work without them but with a few slight tweaks. For example, suppose you take your current develop and start testing a build somewhere, and then you like it and want to release it into production. You actually have a release branch, but it isn't named. It's just the commit ID of what you tested. When you release, simply merge that commit ID from develop into master instead of develop which might be ahead of that commit. That way you won't also merge in any new code that happened on develop after you started testing. Essentially this is identical to making a dedicated release branch, but without actually naming it. The same goes for a hotfix. Typically hotfixes are a minor change in a single commit. I would recommend branching off of master into some branch, but it doesn't have to be called hotfix; any name will do. Then PR that branch into master and merge master back into develop when done, or, as Git Flow points out, if a release branch already exists, then merge master back into release instead of develop (though you could also merge release back to develop too if you want that fix there sooner).

Side Side note: the most common complaint I hear about Git Flow is that it is unnecessarily complex. I find the complexity to be absolutely necessary for some organizations, and of course not necessary for others. You can pick and choose which parts of it you wish to use, and adjust when necessary. If you haven't needed release branches yet that's great- just tweak your workflow to merge in just the commit ID from develop into master when you release. But if you find you need a bugfix against that commit ID, maybe then you could create a release branch on the fly. This was you could get by without dedicated release branches most of the time.

Complainant answered 14/4, 2021 at 15:18 Comment(0)
U
1

Following the git-flow image below : enter image description here

you can go from master to develop if you need to fix some issue that take a lot of time (start a big fix if you have a quick task like fix css , code styling ...). In your case you can start a new feature and when you finish you can make merge to develop using :

  • git merge
  • git rebase
  • git cherry-pick or using git-flow command:
  • git flow feature finish

I hope that can help you to improve your work.

Ulpian answered 14/4, 2021 at 11:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.