gitgitlabgit-workflow

What workflow should I use for parallel feature development? Each feature must be merged into master on its own


I am wondering which would be the best approach in this case:

I have a baseFeature branch derived from master, and multiple feature branches derived from baseFeature. baseFeature has initial changes common to all the new feature branches.

My flow right now is to merge each feature branch back into baseFeature and then merge request baseFeature to upstream master. But this results in multiple features being combined in the same merge request to master (e.g. 10 features in one merge request). I want each feature to appear in master's history as a separate merge commits.

When I try to do separate merge requests from each feature branch, I get

Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing to the same ref

One solution is to use -f. But it says I am not allowed to force push.

I could have each feature be a branch off master and include in each the commits on baseFeature before starting any work. After finishing I would push the branch to master.

Which would be the best approach? are there any possibilities? All I need is to have different merge requests from each feature. But I cannot merge the baseFeature into master since is not reviewed yet.


Solution

  • Now that your question has been clarified, I'll update my answer.

    Updates were rejected because the remote contains work that you do not have locally. This is usually caused by another repository pushing to the same ref

    It means that you are pushing new commits to a branch that has diverged from yours -- i.e. has commits that you don't have. It prevents you from this for your protection. Think about it: Both you and someone else (or maybe you in another context) made changes to the upstream branch. You can't just push the state of your local branch (because that is what push does) and overwrite upstream (well you can, with a "force push" git push -f, but DO NOT do that unless you actually want to overwrite upstream).

    You haven't specified which branch you are pushing that results in this error. Local master to upstream master? Local feature branch to remote feature branch?

    Regardless, since you are using merge requests, you shouldn't be pushing to master anyway.

    Based on what I can tell of your workflow, this is what I think you should be doing:

    1. Sync up your local master with upstream master.[1]

    2. Then get any commits on master not in your feature branch into your feature branch. I strongly recommend that you do this by rebasing your feature branch.[2]

    3. Retest your code. Fix as necessary.

    4. Submit merge request.

    If you don't know about rebasing, there are tons of articles on the web or StackOverflow. git rebase is one of the most important commands you should know.


    [1] Your local master should always look just like upstream. You shouldn't commit changes to it directly. Given your merge-request-based workflow, changes should always flow as follows (simplified):

    [2] You should do steps 1 and 2 regularly if there are changes being made to master. Otherwise you may be doing work on the feature branch that won't work with the latest changes on master.