How to merge two Github Repositories into one new master branch
by bernt & torsten
I run into an issue recently with my co-developer, we had created to repos, we needed to merge the two repos. We are using Github as our main repository, and the first step we would need to do was to find the difference between the two repos, on GitHub, it’s not possible to compare two unrelated repos.
This is what we did in the end, and it worked for us:
- Go to the working directory of your local repo
- Add a remote for the other repo and fetch it
- Compare using
git diff
For example:
cd /path/to/repo
git remote add other URL_TO_OTHER
git fetch other
git diff other/branchname
git diff ..other/branchname # diff in the other direction
cd /path/to/repo git remote add other URL_TO_OTHER git fetch other git diff other/branchname git diff ..other/branchname # diff in the other direction cd path/to/project-b git remote add project-a path/to/project-a git fetch project-a git merge project-a/master # or whichever branch you want to merge git remote remove project-a
There are other ways to do this as well, here is another example:
# Assume the current directory is where we want the new repository to be created # Create the new repository git init # Before we do a merge, we have to have an initial commit, so we'll make a dummy commit touch deleteme.txt git add . git commit -m "Initial dummy commit" # Add a remote for and fetch the old repo git remote add -f Repro_A # Merge the files from Repro_A/master into new/master git merge Repro_A/master # Clean up our dummy file because we don't need it any more git rm deleteme.txt git commit -m "Clean up initial file" # Move the old_a repo files and folders into a subdirectory so they don't collide with the other repo coming later mkdir Repro_A git ls-tree -z --name-only HEAD | xargs -0 -I {} git mv {} Repro_A/ # Commit the move git commit -m "Move old_a files into subdir" # Do the same thing for Repro_B git remote add -f Repro_B git merge Repro_B/master mkdir Repro_B git ls-tree -z --name-only HEAD | xargs -0 -I {} git mv {} Repro_B/ git commit -m "Move Repro_B files into subdir" # # Merge the second branch into the first repo's master branch git checkout master git merge Repro_B
Why It’s Important to Exercise When You’re Over 60
Many of us find ourselves in a pickle as the years pile up. Once reliable sidekicks, our...
A Poem: The Last Time
You never know when it will be,
The last time you ski down slopes of snow,
A Poem: Time Millionaire
When the morning wakes, still and clear,
No more alarms, no more rush....