Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git subtree pull -P whatever <repo> <ref> always merge conflict

The problem: I'm getting a merge conflict every time I try to pull into my subtree even when I have no changes.

What I'm doing:

In subtree-repo

# Make some changes

$ git commit -am 'Changes made'

$ git push origin master

In main-repo

$ git subtree add --prefix public/common {{subtree-repo}} master --squash

# Make some changes

$ git commit -am 'Changes made'

$ git subtree push --prefix public/common {{subtree-repo}} master

In subtree-repo

$ git pull origin master

# Make some changes

$ git commit -am 'Changes made'

$ git push origin master

In main-repo

$ git subtree pull --prefix public/common {{subtree-repo}} master --squash

And this is where things blow up. The pull gives me:

remote: Counting objects: 5, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From {{subtree-repo}}
 * branch            master     -> FETCH_HEAD
   a53e6fc..c078461  master     -> {{subtree-repo}}/master
Auto-merging public/common/README.md
CONFLICT (content): Merge conflict in public/common/README.md
Automatic merge failed; fix conflicts and then commit the result.

So why am I getting a merge conflict when I haven't made any changes?

What I'm trying to accomplish: I have a web project and a mobile project I'm building on Cordova. Because they're both using JavaScript I have several components and models I want to share between the two. I'd like to put these common things in a shared folder between the two of them so I don't have to copy paste. I looked into the pros/cons of submodules and subtrees and decided on subtrees. This is a one-man project right now, but I would like to do things the right way so it can scale.

Note: If you have a suggestion for a better way to accomplish what I'm trying to do, that would be awesome :-)

like image 474
kentcdodds Avatar asked Nov 01 '22 02:11

kentcdodds


1 Answers

Not sure what's causing the problem, but I've determined a better solution for what I'm trying to accomplish:

bower install [email protected]:username/my_repo.git --save

So I'll just be using bower for sharing stuff between repos. I didn't realize you could use a git repository url for a bower component. Pretty sweet I say. Unfortunately this doesn't allow me to make upstream changes from the repo I'm using, but at least I have a super easy way to do it :)


Update

I posted this method on Google+ and Rob Becker mentioned that you could make it even simpler by using a bower symlink:

Try adding in "bower link" to reduce all that copying. You can simply have your shared code in separate repos and set up as bower components as you already have. Then do $ bower link in bs-js-common

This sets up the link. Then in your main project where you have a bower dependency on bs-js-common just do: $ bower link bs-js-common

You will then have a filesystem link from your main projects bower_components/bs-js-common folder to where the actual project repo lives. This lets you see live changes in both places.

like image 198
kentcdodds Avatar answered Nov 08 '22 17:11

kentcdodds