Skip to content

Instantly share code, notes, and snippets.

@anavarre
Last active July 5, 2017 22:05
Show Gist options
  • Save anavarre/7486059ea510e71d24c2 to your computer and use it in GitHub Desktop.
Save anavarre/7486059ea510e71d24c2 to your computer and use it in GitHub Desktop.
Merge 2 Git repositories
#!/usr/bin/env bash
SOURCE_REPO="/local/path/to/source/repo"
REMOTE_NAME="github"
REMOTE_PATH="https://github.com/username/repo.git"
REMOTE_BRANCH="master"
# Prepare source repo.
cd ${SOURCE_REPO}
find . -not \( -name .git -prune \) -exec git rm -r {} \;
git commit -m "Remove source files"
# Merge remote repo files and history into source repo.
git remote add -f ${REMOTE_NAME} ${REMOTE_PATH}
git merge --no-edit ${REMOTE_NAME}/${REMOTE_BRANCH}
# Clean up
git remote remove ${REMOTE_NAME}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment