-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "How to merge multiple git repositories and keep commit history"
- Loading branch information
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# How to merge multiple git repositories and keep commit history | ||
|
||
### Goals: | ||
|
||
1. Merge several separate repos into one. | ||
2. Preserve the complete Git commit history. | ||
|
||
``` | ||
# Before: two repos | ||
repo_a | ||
└── dir_a | ||
└── dir_b | ||
└── dir_c | ||
repo_b | ||
└── dir_x | ||
└── dir_y | ||
└── dir_z | ||
``` | ||
|
||
``` | ||
# After: new repo X containing both a and b | ||
repo_X | ||
└── repo_a | ||
└── dir_a | ||
└── dir_b | ||
└── dir_c | ||
└── repo_b | ||
└── dir_x | ||
└── dir_y | ||
└── dir_z | ||
``` | ||
|
||
### Overview | ||
|
||
This is an overview of the basic steps. | ||
|
||
1. Re-arrange each repo so they can merge without conflicts | ||
2. Add each repo as a remote source for the repo you want to merge into | ||
3. Merge the repos with --allow-unrelated-histories | ||
|
||
### Prepare each repo for merging | ||
|
||
1. make sure you don't have overlapping directories and/or files | ||
if you do, try to rename them or put them in directory with the repo name. | ||
2. Commit and push the changes of the repo | ||
|
||
### Connect the repos | ||
|
||
``` | ||
# Add a remote for and fetch the old repo while on repo_X | ||
git remote add -f repo_a <repo_a URL> | ||
# Merge the files from old_a/master into new/master while in repo_X | ||
git merge old_a/master | ||
``` | ||
|
||
https://gfscott.com/blog/merge-git-repos-and-keep-commit-history/ | ||
https://hacks.mozilla.org/2022/08/merging-two-github-repositories-without-losing-commit-history/ |