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
:
sub
to use a different branch of S
(ie develop
branch)sub
to use a different repository altogetherIs 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.
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.
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.
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.
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.
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.
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