git subtree: possible to change subtree branch/path in a forked repository?
If you used git subtree
(and not git submodule
) to create the subtree, then it's just a normal dir. To switch it to another branch, just delete it and recreate the subtree from the new branch. This is:
git rm <subtree>
git commit
git subtree add --prefix=<subtree> <repository_url> <branch>
That should work without problems.
LearnCocos2D
Author of the Learn SpriteBuilder book published by Apress. Developer of OpenGW, a game world simulation engines / entity component system with Model-View-Controller architecture that can be used with any rendering engine. Developer of Kobold Kit, the Sprite Kit game engine with tilemap support, game components, scheduling and event dispatching, and all the other things missing from Sprite Kit. Developer of KoboldTouch (commercial) and Kobold2D (free), both game engines build on cocos2d-iphone. KoboldTouch adds MVC and component support and even improves cocos2d's own features, such as Tilemap rendering. Author of the Learn Cocos2D book series published by Apress. The latest edition "Learn cocos2d 2" uses cocos2d 2.0 with ARC enabled and also covers Kobold2D. Steffen's main website is Learn Cocos2D.
Updated on June 21, 2022Comments
-
LearnCocos2D almost 2 years
In a repository
A
the foldersub
is included as git subtree of the repositoryS
- pointing tomaster
branch.I have forked repository
A
intoF
. Now I want to do one of the following inF
:- change
sub
to use a different branch ofS
(iedevelop
branch) - or: change
sub
to use a different repository altogether
Is either one of these possible, and if so, how? Will there be any side effects I should know of?
And how can I make sure my subtree change won't be updated in repository
A
when I merge my changes (pull request)? I mean besides isolating commits. - change
-
LearnCocos2D over 10 yearsand that won't be synched upstream? I guess I'll give that a try then.
-
elmart over 10 yearsIt won't be synced upstream. The
<repository_url>
is not saved anywhere; it's just used for the command to know where to get the files from. After that, you get a normal subdir within your repository. -
LearnCocos2D over 10 yearsAh ok, I see that now ... subtree simply "copies" the state of a commit of another repository, as if I had copied it manually (but preserving the commit history and what not). So that doesn't change my original problem of not synchronizing a specific folder between two repositories, but sufficiently answers this question.
-
Jorge Orpinel Pérez over 9 yearsNote: I think it's always best to add a remote before adding and pulling a new subtree. In my experience it works much better and can't be done after you add the subtree. See stackoverflow.com/questions/16829401/…
-
Skulas about 2 yearsSince subtree is a folder you need to add -r to recurse it:
git rm -r <subtree>