Thanks. I ended up getting a trial version of Tower and using the comparison tool to resolve my conflicts. MY BEDROCK/TRELLIS SETUP IS WORKING!!! Yay!!!
@tinytoolbox That’s great news.
Currently, I keep ‘trellis’ & ‘site’ (bedrock + theme) in different git repositories as it was easier for me to merge changes with Tower when the two are separated. My two next big steps are figuring out how to use Cherry Picking and, more importantly, getting each project into one repository and using git Subtrees with the git merge commands from @chrisk2020.
Edit: I now have everything in one repository…much nicer. The GUIs of Tower and SourceTree cannot be easily be used for the subtree git merge. Use the CLI instead.
In my case I had to remove the trailing slash after subtree=trellis, otherwise it gave the error:
fatal: entry not found in tree
Apart from that, so far the method seems to work fine. Thanks for the article @chrisk2020
you definitely want a good diff app and Kaleidoscope is quite good. easy on the eyes. kdiff3 is your free alternative. any other means of resolving a messy merge is insanity.
I haven’t tried this approach yet so I haven’t yet had to deal with merge conflicts, etc. But with this subtree approach is it possible to rebase instead of merge? The idea would be to rebase the entire Trellis/Bedrock/Sage repos with their updates and then apply all your app specific changes on top of those changes. It might help minimize conflicts? Does that conceptually make sense?
FYI - if anyone is using this method and getting this error message:
fatal: refusing to merge unrelated histories
it’s because the default changed in git 2.9; see this SO question.
--allow-unrelated-histories to make the command work again:
git merge -X subtree=trellis/ --squash trellis/master --allow-unrelated-histories
Has anyone tried
git subtree for this? I just updated my project to use this by doing the following:
git remote add trellis https://github.com/roots/trellis.git mv trellis trellis-old git commit -a -m 'Moved trellis to prepare for new subtree setup' git subtree add --prefix=trellis trellis master --squash
Now trellis is at
trellis/ via the git subtree feature, which will be helpful later…
But first you have to copy over all your modifications to trellis from trellis-old.
git diff-tree -r -p HEAD:trellis HEAD:trellis-old
will show you what has changed.
git diff-tree -r -p HEAD:trellis HEAD:trellis-old --name-status
will give you a list of changed files. Decide which ones you actually changed vs. what may have changed in the trellis master. I used my text editor to assemble a list of files I actually wanted to copy in
~/tmp/script.sh, then ran it.
bash ~/tmp/script.sh git add . git commit -a -m 'Copied trellis customizations from trellis-old folder'
rm -rf trellis-old git commit -a -m 'Removed old trellis dir'
Later, if you want to see how your trellis differs from the latest main branch,
git fetch trellis master git diff trellis/master HEAD:trellis --name-status
And the coup de grace, when you want to do an update, it’s as easy as:
git subtree pull --prefix=trellis trellis master --squash
Firstly, thank you for the detailed process.
I ran through it and it all works, but was a little confused by:
It might be helpful to include example contents for that bash script.
Instead what I did was at the point of comparison, opened up Kaleidoscope and opened the new
trellis folder and the
trellis-old folder and managed the changes / copying like that (leaving the
trellis-old folder untouched and only moving things to the
Tested the remaining commands and they worked perfectly.
Following your instructions, I successfully reorganized an existing Trellis setup to use Trellis in a subtree.
It went fine, except that when I
vagrant up , I get an error:
$> vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Checking if box 'bento/ubuntu-16.04' is up to date... A VirtualBox machine with the name 'domain.loc' already exists. Please use another name or delete the machine with the existing name, and try again.
Do I actually need to destroy and recreate the vagrant box every time I update Trellis ?
I simply cloned the trellis repository and left it a normal git repository.
The sites are stored outside, one directory up or even somewhere else (paths can be adjusted).
I pull new changes from the official GitHub trellis repository into my own branch, merging is usually quite easy. Afterwards I test on a fresh staging instance, deploying the sites, then I apply also on production.
I’ve set subtrees for all three. Trellis, Sage and Bedrock.
I finally wanted to update Bedrock as a test. However I can’t get past the merge. This is how it all hapens…
git checkout bedrock
git checkout master
git merge -X subtree=site/ --squash bedrock/master --allow-unrelated-histories
error: Merging is not possible because you have unmerged files.
hint: Fix them up in the work tree, and then use 'git add/rm '
hint: as appropriate to mark resolution and make a commit.
fatal: Exiting because of an unresolved conflict.
I have only done VERY basic Git commands in the past and have read a good amount on the subject. I just haven’t retained what I’ve read
The conflict comes from my .gitignore file conflicting with Bedrocks. As, for reasons I don’t understand, all of Bedrock’s files are on the root folder and haven’t been moved to site/ as when git read-tree is used…
Anybody with a bigger Git memory bank make sense of this? I’m happy to read any and all links.
Hi - apologies for the delay - sounds like you just needed to commit the gitignore before trying the update?
I don’t recall how I managed it. But thanks thanks for the reply. Thanks for that post, by the way. Very helpful!
Tower is now also available for Windows too.
I have had this setup for some time now, but the issue is during updates my changes are basically completely overwritten instead of properly merged. Any ideas?
I’d also like to know how to do this. This subtree method seems to end up being about as effective as downloading a copy of trellis and manually merging the changes with meld.
git subtree is much better than
git read-tree indeed!
It avoids errors such as
refusing to merge unrelated histories.
Having the entire trellis + bedrock + sage tree in your repo might be seen as a downside, but it actually helps you keep tract of which updates you have not yet merged into your own project.
Having setup a new project with a slightly modified fork of trellis (some extra bash scripts added, nothing really modified) and following the first few steps with no issues I get this fatal error when running
git diff-tree -r -p HEAD:trellis HEAD:trellis-old full output here:
$ ls README.md site trellis trellis-old $ git diff-tree -r -p HEAD:trellis HEAD:trellis-old fatal: Path 'trellis-old' exists on disk, but not in 'HEAD'.