![]() It does seem to work, but I need to test it some more. I'm currently trying out a solution that uses git filter-branch to rewrite the merged-in repository history. Is it possible to merge a remote git repository in another one as a subdirectory with individual files coming from the remote repository retaining their history? I tried using the subtree strategy as mentioned in How to use the subtree merge strategy, but after following that procedure, although the resulting repository contains indeed the merged history of the two repositories, individual files coming from the remote one haven't retained their history (`git log' on any of them just shows a message "Merged branch…").Īlso I don't want to use submodules because I do not want the two combined git repositories to be separate anymore. I'd like the resulting repository to contain the merged history of the two repositories and also that each file of the merged-in repository retain its history as it was in the remote repository. The same command should be able to do the job for other version control tools like Azure DevOps, Bitbucket, GitLab, and others on other environments as well.I'd like to merge a remote git repository in my working git repository as a subdirectory of it. with a few lines of git magic, now we have moved the frontend repository in a subfolder to the backend repository including the commit history for both the main and develop branches.Īs we have seen, I did this solution on GitHub using the git command line using git bash on Windows 11. Git read-tree -prefix=Frontend/ -u frontend/develop Git merge -s ours -allow-unrelated-histories -no-commit frontend/develop git clone Įcho "# some code for frontend development" > frontend-development.txtĮcho "# some code for backend development" > backend-development.txt I would suggest not using push until you validate all things play well on the local repository and then if all goes well, push it. I have made a script of all steps I have explained in my article and put all commands together to demonstrate how I did it. as you can see in the Commit history image. Furthermore, we have also moved the commit history from the frontend repository to the backend repository. Git pull -s subtree frontend main Frontend folder Commit historyĪs you can see what we have achieved by using the above-mentioned git snippet, is we have moved the files of the frontend repository to a Frontend folder inside the backend repository. # Final step, I remove the remote repository ![]() Git commit -m "Merge Frontend project to Backend as subdirectory" # Now I commit all changes made with a note Git read-tree -prefix=Frontend/ -u frontend/main # I read the everything from out frontend repo and copy it over to a Frondend folder inside my current repo Git merge -s ours -allow-unrelated-histories -no-commit frontend/main # I merge the commit history of main to my current repo B Git remote add -f frontend C:\Workspace\RepoMigration\frontend\ # I add the frontend repository as remote (remember to check it to main) and give it a name frontend Now the main logic for achieving the goal of repository move is following git script snippet with inline explanation: # from backend repo (B) folder Besides that, I created just some random content in my backend and frontend so I have a kind of commit history for both branches. I create a migration folder and I cloned both empty repositories in my migration folder: git clone įor each repository, I have created 2 branches, a main and develop branch. Make sure, to always backup of your repository before you major change like this, just in case things go bad.īefore going and doing anything in my production repository, I created 2 sample repositories in GitHub, one called backend and the other the frontend. So in addition to commits history, we need to do the same for both branches. In addition the A repo has main and develop branches, as well as the B repo. Now in my case, I wanted to keep track of my commit history from (A). ![]() This would work but without moving the commit history. I have recently met a nice challenge of moving a frontend repository let’s call it (A) with its commit history to an existing backend git repository let’s call (B).Īt the begging of this challenge, I was thinking to clone repository A and copying it into a subfolder in repository B.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |