Best practice for combining two repos into new Trellis+Bedrock Repo

Hi folks,

I’m pretty new to git, and don’t want to screw things up as this is already a live project in Github.

I have a theme repo with Sage 8 in it, and a custom plugin repo. I’d like to pull them together into one new site repo and keep the commit history for both if possible.

I found this gist. Is this the right way to do it? If I clone the two repos first and then combine the clones will the originals stay intact (incase I screw something up?)

Or is it better to turn the theme repo into the Trellis + Bedrock repo and just have the custom plugin repo as a dependency?

Many thanks!

It sounds like you want to take an existing site with a Sage 8 theme + a custom plugin and use it with Trellis/Bedrock; I’d suggest creating a new repo, adding Trellis & Bedrock per then using the sub-tree merge on the Sage 8 repo. Keep the custom plugin separate and add it to your project via composer.json. The gist you linked looks fine though I’m by no means an expert on sub-tree merging, but in the end you’d do something like this:

// From gist
$ mkdir new_parent_project
$ cd new_parent_project
$ git init
$ touch .gitignore
$ git commit -am "initial commit"
// Add Trellis
$ git clone --depth=1 && rm -rf trellis/.git
// Add Bedrock
$ git clone --depth=1 site && rm -rf site/.git
// Merge theme repo per gist
$ git remote add -f sageRepo
$ git merge --allow-unrelated-histories -s ours --no-commit sageRepo/master
$ git read-tree --prefix=site/web/themes/sageRepo -u sageRepo/master
$ git commit -m "merging sageRepo into site/web/themes/sageRepo"

I would either fork the sage repo, and clone the fork, if you want to keep it as a sub-tree (see the “Pulling In Updates” section at the end of the gist) or delete the remote from the new project ($ git remote remove sageRepo) once you’ve added it. Either way, that will let you avoid any changes to the originals. If you don’t fork the repo, and leave the remote, you could change the original (intentionally or otherwise) if you make changes and push them upstream.

As far as the plugin, see this blog post for how to make it accessible via composer:

1 Like

Awesome, thanks! Forking it is the safety step I was missing. I didn’t know about removing remotes either.

1 Like

Just looping back in to add a slight correction:

$ git read-tree --prefix=site/web/themes/sageRepo -u sageRepo/master
puts the theme one directory too high - we want it in site/web/app/themes/sageRepo