Roots Discourse

Create a Roots Project Working with Git Subtrees

Repo example

I created this bash script that initialize a Roots based project, using Trellis, Bedrock and Sage. Working with Git Subtrees

Run on the project folder:
https://gist.github.com/caco26i/f902bedcf886e5d907f016478db3495f

#change de URL of our initialized repo
repo=<repo_url.git>

#tool from roots.io 
tools=(trellis bedrock sage) 

#folder structure for the tools
subtrees=(trellis site site/web/app/themes/sage) 

#init repo
git init
git remote add origin ${repo}
touch .gitignore
git add .
git commit -m "initial commit"

#create the project
count=0
for tool in ${tools[@]}; do
  git remote add ${tool} https://github.com/roots/${tool}.git
  git fetch ${tool}
  git checkout -b ${tool} ${tool}/master
  git checkout master
  git read-tree --prefix=${subtrees[$count]}/ -u ${tool}/master
  git commit -m "add ${tool} subtree"
  git push origin master
  count=$(( $count + 1 ))
done

To keep our projects updated easily

Update Trellis example:

git checkout trellis
git pull 
git checkout master 
git merge -X subtree=trellis/ --squash trellis/master 
git commit -m "Update trellis from trellis/master"

Update Sage example:

git checkout sage
git pull 
git checkout master 
git merge -X subtree=site/web/app/themes/sage/ --squash sage/master 
git commit -m "Update sage from sage/master"
9 Likes

Please see this post which mentioned a issue and fix for fatal: refusing to merge unrelated histories issue: Best practices to update Trellis