git fetch master-project
git checkout master
git merge --allow-unrelated-histories master-project/master`
Conclusion
If the above is too complicated and you’d just want to incorporate the changes from the upstream project once, there is no shame with just copying the source tree from one git repo to the other and committing it as “Vendor updates”.
We do that for third-party sources whenever Git subtrees won’t work well enough, or we’ll only need partial content of the repository, e.g. a minified JS file, and not the entire source tree.
For you to learn - get to know more about Git. There’s the online book available, and my employer has open sourced their GitLab training too.
https://git-scm.com/book/en/v2
https://github.com/NETWAYS/gitlab-training/releases
Cheers,
Michael
Edit: Updated from feedback below.
Hi again.
Your description is great. Unfortunately, the merge is still not working. However, if I commit after the merge, I don’t have the files in the branch directory.
git checkout origin/template
ls -la
drwxr-xr-x 3 user user 4096 Jan 9 14:34 templates
git checkout master-project/releasX
ls -la
drwxr-xr-x 8 user user 4096 Jan 9 14:49 admin
drwxr-xr-x 8 user user 4096 Jan 9 14:49 inkl
git checkout origin/template
git merge --strategy=ours --allow-unrelated-histories master-project/releasX
git checkout origin/template
ls -la
drwxr-xr-x 3 user user 4096 Jan 9 15:00 templates
But by the checkout to origin/template I get a massage like:
Previous position of HEAD was 671ce4312 Merge branch 'merge commit from the master-projekt'
HEAD is now at 2f4370123 'my last commit before the template+master-projekt merge '
Do you have an idea?
Thanks again.
That workflow doesn’t make sense. The first command brings you into a detached head without any branch target.
You really need to change into your local master branch inside of the current project and then run the merge command.
If that’s not master
, but template
, also fine. But omit the origin/
prefix, this must not be used here.
Committing after a merge isn’t necessary, unless you made local changes after the merge.
Cheers,
Michael
Thanks again for your answer!
The “origin” was only that you see that I in the ride projekt.
If I do it without the commit I get this:
git checkout master
git merge --strategy=ours --no-commit --allow-unrelated-histories master-project/releasX
> Automatic merge completed; stop before committing as desired
ls -la
> drwxr-xr-x 3 user user 4096 Jan 10 8:30 templates
If I merge some other after this from by template-projekt in the master I get this:
git checkout master
git merge someother
> fatal: you have not completed your merge (MERGE_HEAD exists).
> Please commit your changes before performing the merge.
If I do it with the commit I get this:
git checkout master
git merge --strategy=ours --allow-unrelated-histories master-project/releasX
> Merge made by the 'ours' strategy.
ls -la
> drwxr-xr-x 3 user user 4096 Jan 10 8:05 templates
But I never get the output like with a project internal merge.
git checkout master
git merge someother
> Update 7d4c19a..2f43703>
> Fast-forward
> testfile.txt | 6+
> create mode 100644 testfile.txt
ls -la
> drwxr-xr-x 3 user user 4096 Jan 10 8:05 templates
> -rw-r--r-- 10 user user 4096 Jan 10 09:10 testfile.txt
Do you have any ideas?
Really thank you!
aaaaaaah. Sorry, I overlooked the --no-commit
parameter, that tells Git to halt and create your own merge commit. I normally don’t use that parameter, should drink more coffee when copying things.
Hm, the merge is weird. It might be the case that --strategy=ours
prevents the combined merge. Please try to remove that parameter as well
Cheers,
Michael
git clone https://gitlabserver/group/own-templates.git
cd own-templates
git remote add master-project https://gitlabserver/othergroup/master-project.git
git fetch master-project
git checkout origin/branch
git merge --allow-unrelated-histories master-project/branch
ls -la
drwxr-xr-x 8 user user 4096 Jan 13 10:00 admin
drwxr-xr-x 8 user user 4096 Jan 13 10:00 inkl
drwxr-xr-x 8 user user 4096 Jan 13 10:00 templ
cd templ
ls -la
drwxr-xr-x 8 user user 4096 Jan 13 10:01 ProjektTempl
drwxr-xr-x 8 user user 4096 Jan 13 10:01 OwnTempl
Thanks!