简体   繁体   中英

Merge upstream in a subdirectory of my git repo

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:

  1. Clone both repo on your machine

    $ git clone Repo1

    $ git clone Repo2

  2. Copy the content of Repo2 to a subfolder. Go to the folder Repo2 and apply the following steps: Create a subfolder Repo2

    $ mkdir Repo2

  3. 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

  4. Commit and push those changes to git

    $ git commit -am '[REPO-2] Move content to a subfolder'

    $ git push origin master

  5. 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)

  6. Fetch Repo2Temp, the temp repo we created in the previous step

    $ git fetch Repo2Temp

  7. Merge Repo2Temp with Repo1

    $ git merge Repo2Temp/master

  8. delete the remote Repo2Temp

    $ git remote rm Repo2Temp

  9. 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM