Merging_Two_Repos
Merging two repositories
Thank you for the helpful guide/tutorial. I couldn't remember all those commands. So I think it would be useful to sum it up for others here.
- Check remote origins for main repository
git remote -v
git remote add <RemoteName> <RemoteURL>
- Fetching the newly added second repo to our main repo file location
git fetch <RemoteName>
- Check to see whether remote is available with
git remote -v
- Create a new branch with
git checkout -b <NewBranchName> <Branch(RemoteName)/master>
Move all the files into a subdirectory so there aren't any conflicts with names (git mv) and commit the files.
(No need to also move the hidden .git folder in the subdirectory)
git commit -m "moved"
If you get any Merge issues like “Un tracked working tree files would be overwritten by merge”
You could git stash your branch and merge commit and then git stash apply so that you won’t have any merge conflicts or else you could just commit the files and solve merge conflicts using VSCode / Vim.
git stash
git stash apply
- Checkout the master branch
git checkout master
- Merge newly created branch of another repo into the main repo master branch using
git merge <NewBranchName> --allow-unrelated-histories
- Cleanup everything by removing remote and branch
git remote rm <RemoteName>
git branch -d <NewBranchName
- Check to see whether everything is correct with
git remote -v
git branch -a -v
git status
- Push all of these local changes to remote origin
git push
One more Guide Link