Git merge repository
When working on a project with multiple team members having separate repositories for each team, at some point in time we come across a situation where we want to combine these separate repositories into one master repository to deploy all the work using a single repository.
Trying to merge various repositories into one, or even preserve their precious commit history, may seem difficult, but it really isn't. In this article, we'll explain in detail, step by step, how to merge separate repositories into one master repository.
Steps to merge repositories in Git
Let's assume we have three repositories: repo A
and repo B
, and then we have a repo Z
, and we want to merge A
and B
. Let's assume we have repo Z
another thing currently in the directory, and we want to merge these two repositories A
and B
into one Z
.
Let's assume one more thing; repo Z
it's the master branch of the repository.
1. Add remote URL
In this step, we will run git remote add
the command with the property f; this will add a remote for repo A, which we will name repo A.
git remote add -f remote-A .
With options -f
, the command is processed immediately after setting the remote information git fetch <name>
.
We will follow the same procedure as above for repo B.
git remote add -f remote-B <repo-B-URL>
2. Merge files and folders
Now, we will merge the files from repo A into the current branch (repo Z) using the following command.
git merge remote-A/master –allow-unrelated-histories
Here we will add --allow-unrelated-histories so that Git will allow merging unrelated histories.
The same process will be repeated on repo B using the following commands.
git merge remote-B/master --allow-unrelated-histories
If there are some conflicts after running the above commands, we will resolve them and then commit the merge successfully.
3. View commit history
We will run the following command git log to view the merged commit history, which will be our last step to view all merge histories of each repository.
git log
For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.
Related Articles
Ignore everything except certain files in Git
Publish Date:2025/04/20 Views:151 Category:OPERATING SYSTEM
-
This article outlines the steps to make Git ignore all but a few files in a Git repository. The .gitignore file is a useful Git utility that allows us to tell Git which files to track and which files not to track. If you want your .gitignor
Git push to another branch with a different name
Publish Date:2025/04/20 Views:57 Category:OPERATING SYSTEM
-
git push It has a rich set of options that allow you to use the full power of Git. One of them is its source:destination refspecs parameters. We use these git push to go to a specific branch with a name of our choosing. Finally, we'll see s
Issues to note when installing Apache on Linux
Publish Date:2025/04/08 Views:78 Category:OPERATING SYSTEM
-
As the most commonly used web server, Apache can be used in most computer operating systems. As a free and open source Unix-like operating system, Linux and Apache are a golden pair. This article will introduce the installation and use of A