I use Git Subtree like below:
git subtree add --prefix=directory_destination_path --squash [email protected]:kicaj/projectname.git master
But in path: directory_destination_path
copy all repo from projectname.git
How to copy to directory_destination_path
only subdirectory or only some file from projectname.git
?
EDIT:
One more question:
How to update (automatic) files changes in both repositories were still the same? It is possible?
git subtree allows you to nest a repository as a subdirectory inside another. It's one of the various options for managing project dependencies in Git projects. You add a subtree to an existing repository where the subtree is a reference to another repository URL and branch/tag when you wish to utilize it.
Subtree splitFirst you split a new branch from your history containing only the subtree rooted at <prefix>. The new history includes only the commits (including merges) that affected <prefix>. The commit in which where previously rooted in the subdirectory <prefix> are now at the root of the project.
Specify 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.
About subtree merges Typically, a subtree merge is used to contain a repository within a repository. The "subrepository" is stored in a folder of the main repository. The best way to explain subtree merges is to show by example. We will: Make an empty repository called test that represents our project.
If I understand, you seem to want to only merge in a certain directory of a different repository, and you want it to be a subtree in your repository. I am going to call the directory of interest in the project.git path_of_interest_in_project
and call the destination in your repo directory_desination_path
.
Try adding the remote project.git as a remote, then checking out one of its branches locally. Then use git-subtree split
to split out just the directory of project.git you are interested in. After that merge it into your repo using subtree merge.
git remote add project [email protected]:kicaj/projectname.git git branch project_master project/master
The branch project_master should now store the entire history of your project.git repo.
Then you'll need to use the git-subtrees-split
process.
git checkout -f project_master git subtree split --squash --prefix=path_of_interest_in_project -b temp_branch
There should now be a branch called temp_branch
containing just the directory you are interested in. Now you can perform a git-subtree-merge
to bring it all into your repo.
git checkout -f master git subtree merge --allow-unrelated-histories --prefix=directory_destination_path temp_branch
This should merge in the temp_branch into your master branch.
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