I am working in a company and we decided that we want to use git more properly. I am responsible for integrating dev branch into main branch, and I am a confused as to how to correctly merge in different scenarios.
How we work now: developers would simply rebase their feature branches upon dev
branch. Once finished they'd submit a merge request to dev
branch. Then, I would check the code (We are a small team), and accept merge request. After that they'd simply delete feature branch. When dev
branch was properly tested, I would create a merge request to main branch in GitLab, assign it to myself and approve it. This creates a commit on the main
branch:
Merge branch 'dev' into 'main'
However, now the dev
branch is one commit behind main
. How do I best fix this? Up untill now I would simply merge main
into dev
again but this seems cumbersome and strange as their is now another commit in my dev
branch;
Merge branch 'main' into 'dev'
I could also rebase dev on main but I have learned "thou shallt never rebase public branches"
This SO question tells me the proper way is to first merge main into dev, to make sure main branch stays clean. Would this be the best way of achieving dev --> main
merges?
And is any of this influenced by the notion that git fast-forwards merges by default? I read that a fast-forward merge occurs when there is a linear path from the current branch tip to the target branch. This would imply that, when the dev
branch is simply ahead x
of commits to main
when merging, and no commits were made to main in the mean-time (as is common in our work since we technically only commit to main
from dev
), the merge would automatically be a fast-forward merge? Is this behavior problematic for merging dev
into main
, and should I use the -no-ff
flag when merging?
If I get it correctly, a fast-forward merge integrates the dev
commits into the main
branch, whereas a --no-ff
merge causes the merge to always create a new commit object, even if the merge could be performed with a fast-forward (Source: This SO question). Does this mean that a ff merge does not create a commit, when dev is simply ahead x
commits to main? How would I then push the merge upstream after merging branches locally? Should I even merge dev and main locally or simply keep using gitlab web interface for this?
Needless to say, I am very confused by all this. Would be great if somebody could clear things up.