Resolving Git Subtree Merge - Entry Overlaps Error - Cannot Bind
This blog article provides a solution to working with git subtrees when you encounter a 'cannot bind' error or subtree merges into the wrong folder.
This article doesn't cover setting up subtrees or compare it to submodules. There are a number of good articles available. These are the guides I followed to get setup with subtrees:
- Alternatives to Git Submodules: Git Subtree - In-depth and provides more comparison between subtree and submodule.
- Subtree Merging and You - Excellent walk through dealing exclusively with submodules. This was my favorite reference.
- Kernel.org - How to use the subtree merge strategy - Very succinct
They all follow a similar pattern and don't mention any gotcha's when setting up subtrees. According to the guides the commands needed for my repository should be:
git remote add -f mysubreponame C:\repos\shared-project-code
git merge -s ours --no-commit mysubreponame/master
git read-tree --prefix=location/toplace/subtree/mysub/ -u mysubreponame/master
git pull -s subtree mysubreponame master
All of these guides worked the first time through but subsequent attempts to merge from the subtree into my repository resulted in the merge going into the wrong subdirectory. No problem, right? Simply re-issue the command that was responsible for merging my subtree into the correct directory.
c:\repos\mypoject>git read-tree --prefix=location/toplace/subtree/mysub/ -u mysubreponame/master
error: Entry 'location/toplace/subtree/mysub/readme.txt' overlaps with 'location/toplace/subtree/mysub/readme.txt'. Cannot bind.
Trying to fix the bind error was actually the wrong place to try and fix the merge issue. The solution involved changing the git read-tree step. This stack overflow article revealed an un-documented option for the git pull command. The -Xsubtree parameter specifies which directory the subtree pull should go into instead of relying on git to try and find it. Changing my final pull command to this merged the subtree changes into the correct directory:
git pull -s subtree -Xsubtree=location/toplace/subtree/mysub mysubreponame master
I hope this guide helped you find the correct place to resolve your git read-tree bind errors and get your subtree merges into the correct subdirectory.
Leave a comment