Feature branch is usually used for developing new features or fixing bugs. So for different features/bugs you should use different feature branches and merge a feature branch into main branch until it is finished.
As you showed the process for feature-A-V1
and feature-A-V2
, if the two feature branches developed for different features, you should do as you showed (they worked as short living branches). But the two branches developed for the same feature (feature-A), you should merge until feature-A is finished. In a way, we call it long living feature branch.
Working with long living branches, usually follow these steps:
1.Assume feature-A
branch is checked out from production
, and you are working on feature-A
branch.
A---B---C production
\
D feature-A
2.During developing on feature-A
branch, other developers update production
branch, and the structure likes:
A---B---C---G---H production
\
D---E---F feature-A
3.After you finish developing feature-A
branches, and before push and create PR, you can rebase feature-A
branch to make sure it based on the latest version for production
branch. You can use the commands:
git checkout feature-A
git pull origin production --rebase
And the structure will look like:
A---B---C---G---H production
\
D'---E'---F' feature-A
Now you can push feature-A
to remote and create a PR to merge it into production
branch.
And there has a successful branching module, you can refer.
Update
Since you need to merge and deploy feature-A-v1
, and fix additional bugs but don't want to create new feature branch for this situation. You can checkout to feature-A-v1
branch, and fast forward it by merge production
into feature-A-v1
(feature-A-v1
will also point to commit O
in below graph).
A---B---C---M---O production
\ /
D---N feature-A-v1
A---B---C---M---O production, feature-A-v1
\ /
D---N