Skip to content

Instantly share code, notes, and snippets.

@clody69
Created September 6, 2016 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clody69/8775641b69484e03aef62793c0ad3e84 to your computer and use it in GitHub Desktop.
Save clody69/8775641b69484e03aef62793c0ad3e84 to your computer and use it in GitHub Desktop.
# Instructions how to transfer several directories from one repo to another
# while preserving the history
git clone <git dest> dest
git clone <git src> src
# Prepare the source repo
cd src
git checkout <branch from where to copy the direcoties>
# For safety remove the original remote
git remote rm origin
# If only one directory
# git filter-branch --subdirectory-filter <directory to kepp> -- --all
# If multiple direcotries
git filter-branch -f --prune-empty --index-filter 'git rm --cached -r -q -- . ; git reset -q $GIT_COMMIT -- <dir a> <dir b>' -- --all
# Moving the directory to a different location while preserving history
~/git-mv-with-history.sh <old file>=<new file> <old file>=<new file>
# Merge the changes in the dest repo
cd ../dest
git remote add external ../src/
git checkout <branch where to merge>
git pull external <branch from the src repo> --allow-unrelated-histories
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment