I'm trying to create a gitsubtree of an existing repository, for example:
-> projectA/projectB
Project A is the parent, i want to add project B as a git subtree.
git subtree -P projectB ssh://[email protected]/projectB.git master
But it fails, and shows the following message:
prefix 'projectB' already exists.
I don't want to download all the repository again, I just want to add this directory to my gitsubtree.
This directory project B isn't tracked by Project A git.
thanks in advance
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.
git subtree lets you nest one repository inside another as a sub-directory. It is one of several ways Git projects can manage project dependencies. Why you may want to consider git subtree. Management of a simple workflow is easy.
git subtree split lets you specify a 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.
You can add projectB as a subtree of projectA using vanilla git
(you don't need git subtree
).
cd projectA
git remote add projectB_remote [email protected]/projectB.git
git fetch projectB_remote
git checkout -b projectB_branch projectB_remote/master
git checkout master
git read-tree --prefix=projectB/ -u projectB_branch
Explanation
projectA
repo.projectB_remote
with projectB's url.projectB_remote
without merging.projectB_branch
; bring in the projectB_remote/master
files.projectA/master
.projectA/master
that contains a checkout of the projectB_branch
.Resultant Directory Structure
projectA
projectB
other.txt
project.txt
A.txt
files.txt
See http://www.git-scm.com/book/en/v1/Git-Tools-Subtree-Merging
When adding a subtree, it seems that the prefix (subdirectory in which you will add the subtree) cannot already exist.
I worked around this problem by checking-out to a commit before this subdirectory existed, doing the git subtree add, and then merging with the branch that contained my old subdirectory contents.
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