Created
June 10, 2014 20:43
-
-
Save petemcw/a3292cb65851ecfc0e26 to your computer and use it in GitHub Desktop.
Quick cheat sheet for merging two separate repositories while retaining commit history.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Basic process for merging two Git repositories while retaining commit history. | |
# - This seems to work pretty well for migrations to Pantheon | |
# | |
# Clone the repository that will be the final origin | |
git clone <repository_uri_1> <local_dir> | |
cd <local_dir> | |
# Add the second repository as a remote | |
git remote add <remote_name> <repository_uri_2> | |
git fetch <remote_name> | |
# Create a new branch based off the secondary repository | |
git branch <branch_name> <remote_name>/<remote_branch> | |
git checkout <branch_name> | |
# | |
# Perform any modifications to this branch that need to be done | |
# before merging into the final repository. | |
# | |
# Merge the secondary repository branch into the final repository and clean up. | |
git checkout master | |
git merge <branch_name> | |
git -D <branch_name> | |
git remote remove <remote_name> |
Also, as of GitHub 2.9, the final git merge command will need to be:
git merge --allow-unrelated-histories <branch_name>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The second-to-last line does not work and I think should be:
git branch -D <branch_name>