Skip to content

Instantly share code, notes, and snippets.

@davereid
Forked from anavarre/merge_git_repos.sh
Last active August 29, 2015 14:06
Show Gist options
  • Save davereid/20cc649a2fc63b6632ff to your computer and use it in GitHub Desktop.
Save davereid/20cc649a2fc63b6632ff to your computer and use it in GitHub Desktop.
#!/bin/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