Exercise - Merging small projects
Two previously independent repositories are to be merged into one large repository while preserving their history.
Tips
- With
fetch
(andpull
), you can also fetch history from foreign repositories without a common history with the current repository (keyword unrelated histories). merge
(andpull
) normally refuse to integrate unrelated histories- However, you can force this with
--allow-unrelated-histories
.
- However, you can force this with
git mv
moves files and directories, e.g.,git mv file1 file1 targetdirectory
.subtree add --prefix=<target-directory> <source-repository> <source-branch-or-version>
: Embed another repository in a subdirectory.- If you don’t want to take over the entire history, you can specify
--squash
. - Attention:
subtree add
performs a merge onHEAD
and therefore cannot be executed in an empty repository without commits.
- If you don’t want to take over the entire history, you can specify
Setup
Two repositories
backend.git
ui.git
are already present.
Step 0 - START
Step 1 - Merge `git subtree`
Start in directory git-uebungen/aufgaben/<unknown>
.
- Create a repo
application
with one commit. - Add
backend.git
in a subdirectorybackend
. - Add
ui.git
in a subdirectoryui
. - Examine the directory structure and commit graph
Step 2 - Merge with `fetch`, `mv` and `merge`
Start in directory git-uebungen/aufgaben/<unknown>
.
UI and backend should be merged in a new clone gesamt
. Follow the instructions in the chapter “Merging small projects”. Then examine the directory structure and commit graph.