I have the remotes Foo and Bar. Foo is a web application that has lots of directories, relevant amongst them is /public
which contains assorted files and other directories.
Bar is a set of libraries and whatnot used on the front end, as such, it should go in /public/bar
in Foo. Foo has no files there.
That would all be piece of cake with either submodules or subtree merge. However…
Bar's tree is messy, it has all sorts of pre-production files like PSDs and FLAs, and the only really useful part of it is what is inside its /www/tools
.
So, what I want to do is merge Bar's /www/tools
into Foo's /public/bar
, and pretend the rest of Bar's tree doesn't even exist.
Can do?
(I would suppose this is very similar to how you merge from a project that originally merged yours as a subtree. Which I don't know how to do, either.)
About subtree merges We will: Make an empty repository called test that represents our project. Merge another repository into it as a subtree called Spoon-Knife . The test project will use that subproject as if it were part of the same repository. Fetch updates from Spoon-Knife into our test project.
Splitting the Original Repository The subtree commands effectively take a folder and split to another repository. Everything you want in the subtree repo will need to be in the same folder.
The idea here, is to merge "one of your local branch" (here anotherLocalBranch ) to a remote branch ( origin/aBranch ). For that, you create first " myBranch " as representing that remote branch: that is the git checkout -b myBranch origin/aBranch part. And then you can merge anotherLocalBranch to it (to myBranch ).
I've successfully done this using the following commands (rewritten for your scenario).
$ git remote add Bar /path/to/bar
$ git merge -s ours --no-commit Bar/master
$ git read-tree --prefix=public/bar -u Bar/master:www/tools/
HUGE WARNING! I'm still in the process of figuring out how to do fetch/merge from Bar. This will bring in everything just once.
My current way of merging changes is like so:
$ get fetch Bar
$ git pull -X subtree=public/bar Bar master
This will leave you with conflicts saying that a ton of files have been removed, you can just git rm
them and then git commit
.
I'm certainly open to suggestions on a better way to pull changes.
Since this is an old thread, I should add that I'm running Git 1.7.9.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With