I've got a git repo, let's say "projectroot". Now I want to merge from an upstream remote. I want to merge this content into a specific directory of my "projectroot". For instance, into "projectroot/html".
How can I do this? If I just do git merge upstream/branchname it will merge it into the "projectroot" directory. But it has to go in "projectroot/html".
It's important to keep the "projectroot" as my git repo.
Kind regards
Suppose you have 2 repositories Repo1 and Repo2 and you want to move Repo2 as subdirectory of Repo1 .
To achieve that we will move the content of Repo2 into a subfolder under Repo2 and then merge Repo1 and Repo2 .
Below are the detailed steps:
Clone both repo on your machine
$ git clone Repo1
$ git clone Repo2
Copy the content of Repo2 to a subfolder. Go to the folder Repo2 and apply the following steps: Create a subfolder Repo2
$ mkdir Repo2
Move everything from the parent Repo2 to the child Repo2 (except the .git folder) and stage the files (the added folder and deleted file(s)) for a later commit
$ git stage Repo2/
$ git stage README.md
Commit and push those changes to git
$ git commit -am '[REPO-2] Move content to a subfolder'
$ git push origin master
Go to the folder Repo1 and do the following: Add a remote branch with the content of Repo2
$ git remote add Repo2Temp (path_to_Repo2)
Fetch Repo2Temp, the temp repo we created in the previous step
$ git fetch Repo2Temp
Merge Repo2Temp with Repo1
$ git merge Repo2Temp/master
delete the remote Repo2Temp
$ git remote rm Repo2Temp
Push the changes to the server
$ git push origin master
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.