Let's say you have the following setup in gitlab:
- Gitlab Group
Developments, of which there is a SubgroupSubgroup, which in turn containsTemplate project Xwhich provides a general structure for all projects of the groupDevelopments. The subgroup is simply used as that's needed to make use of gitlab's project templates. - You then create a
Project Yin the groupDevelopmentsfrom theTemplate project X. - You then create a
Project Zin the groupDevelopments, also from theTemplate project X.
During development, you then notice a bug in Project Y in a file that is also present in the Template project X. What I thus want to do now is:
- Fix the bug in
Project Y, let's say withinCommit 123. git add remoteto add theTemplate project Xas an additional remote your localProject Y(thus now havingoriginandtemplate-project-xwhen callinggit remote -v).- Create a new branch
fixfrom starting pointtemplate-project-xwith--no-trackwhile inProject Y. - Add the
Commit 123into thefixbranch (e.g. usinggit format-patchandgit am). - Push the
fixbranch to thetemplate-project-xremote with the-uflag.
Until that, everything works perfectly, and I have the patch of the concerned commit within the newly created fix branch in my gitlab Template project X showing up.
The last missing piece in this workflow is: How can I create a merge request of the pushed template-project-x/fix > template-project-x/main ?
When I, after the sequence of actions described above, run the following command while still in Project Y:
glab mr create --repo <GIT-URL-TEMPLATE-PROJECT-X> --assignee <assignee-name> --draft --remove-source-branch --reviewer <reviewer-name> --source-branch fix --target-branch main
I get:
Creating draft merge request for fix into main in template-project-x
Failed to create merge request. Created recovery file: /Users/.../mr.json
Run the command again with the '--recover' option to retry.
ERROR
Post https://gitlab.com/api/v4/projects/.../merge_requests: 422 {message: [Source project is not a fork of the target project]}.
Does this mean that I cannot create a merge request using glab for a project A while in project B ?
I have found similar questions in the gitlab community, but without a real answer.
git cherry-pickshould be able to handle (if the contents of the commits involved are similar enough).cherry-pickbeats format-patch/am because it has context about the relationship between the ancestor of the commit you are cherry-picking and where you want to apply it. To give an example, differences in line numbers, in my experience, can break a patch, whereas cherry-pick will easily handle that case.