Hi,
so you are having two Git repositories, and the master-repo
should be included into your Git repository tree.
Git submodules or subtrees don’t really qualify for this, since they expect to live in a sub directory. So you’ll directly need to merge two repository histories together.
Merge two repositories
The following describes a one-shot merger. Important: This retrieves the entire history of the master project which may render your project’s history unreadable.
Local own repository
git clone https://gitlabserver/group/own-templates.git
cd own-templates
Add secondary remote repository config
git remote add master-project https://gitlabserver/othergroup/master-project.git
git fetch master-project
Now the following remotes exist:
-
origin
as default for our repository
-
master-project
pointing to the other repository where we want to import data from.
The git fetch updated the local index for changes, but did not pull any commit history yet.
Branches and Merging
Using the detail that you can access <remote>/<branch>
of any configured and fetched remote, you can immediately access master-project/master
as a reference and merge source.
git checkout master
git merge --allow-unrelated-histories master-project/master
Future Updates
Same as above but without the remote configuration step.
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.
Cheers,
Michael
Edit: Updated from feedback below.