Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git subtree: possible to change subtree branch/path in a forked repository?

Tags:

In a repository A the folder sub is included as git subtree of the repository S - pointing to master branch.

I have forked repository A into F. Now I want to do one of the following in F:

  • change sub to use a different branch of S (ie develop 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.

like image 422
LearnCocos2D Avatar asked Aug 30 '13 15:08

LearnCocos2D


People also ask

How does git subtree work?

Adding a subtreeSpecify the prefix local directory into which you want to pull the subtree. Specify the remote repository URL [of the subtree being pulled in] Specify the remote branch [of the subtree being pulled in] Specify you want to squash all the remote repository's [the subtree's] logs.

How do you push a subtree?

subtree : push: allow specifying a local rev other than HEAD ' git push '(man) lets you specify a mapping between a local thing and a remot ref. So smash those together, and have git subtree push let you specify which local thing to run split on and push the result of that split to the remote ref.

What is git subtree split?

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.

What is git subtree merge?

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.


1 Answers

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.

like image 130
elmart Avatar answered Oct 03 '22 16:10

elmart