Skip to content
TURNKEYGNU / LINUX
AppsDocumentationBlogScreenshotsGitHubTurnKey Hub
文English
EnglishDeutschEspañol日本語Português中文
Home/Blog/Git tip: how to merge multiple projects into one big repository

From the project

Git tip: how to merge multiple projects into one big repository

By Liraz SiriOctober 4, 20152 min read
gittips

A while back I decided it would be a good idea to combine a loose collection of related Git repositories into one big Git repository.

The rational for this was that I noticed that often the same logical change had to be broken up into multiple commits across these previously separate repositories in a way that made it difficult to track which changes were part of the same change. In other words it artificially fragmented the commits and made revisions harder to track.

I wanted future changes to go into one big Git repository but I also wanted to preserve the history of the component repositories.

Once I figure out how to do it, this was very easy to implement. I simply moved the contents of each repository so that everything was under a single subdirectory, like this:

cd foo/
mkdir foo
git-mv * foo
git-add .
git-commit -v -m "moved everything under foo/"

Once I did that for all the repositories (e.g., foo, bar), I created a new repository and merged all of these components repositories into that single repo:

mkdir merged-project
    cd merged-project
    git-init
    git-pull ../foo
    git-pull ../bar
            ...

When all of this is done, you get one big repository has the component projects not as separate repositories but simple sub-directories in the big repository, with all of the commit history perfectly preserved.

Comments (1)

Good point

Reply 1 2018-07-18

Just looking at it it appears that in the mv line, the asterisk would indeed capture the intended target directory too (and produce the error you note).

I reckon when he did it for real, he explicitly moved the directories/files. Then overlooked that when he generalised the procedure as example.

Keep exploring

Find your next server

Browse ready-to-use appliances by the job you need to do.

Explore the app library
TURNKEYGNU / LINUX

Own your infrastructure without starting from scratch.

Explore TurnKey
AboutDocumentationFAQBlogGitHub
Free and open sourceSecure by defaultReady to deploy