Skip to content

Instantly share code, notes, and snippets.

@frainfreeze
Last active July 11, 2023 23:32
Show Gist options
  • Save frainfreeze/f69de1a52024b02fc308afe28ea764af to your computer and use it in GitHub Desktop.
Save frainfreeze/f69de1a52024b02fc308afe28ea764af to your computer and use it in GitHub Desktop.
Merge github repos, preserving history
Clone and merge github repo into archive as a subfolder, preserving commit history
# before running the script prepare archhive folder in the same location
export REPONAME={HelloWorldRepo}
export GHUSER={UsersUsername}
git clone git@github.com:$GHUSER/$REPONAME.git
cd $REPONAME
git filter-repo --to-subdirectory-filter $REPONAME
cd ../archive
git remote add $REPONAME ../$REPONAME
git fetch $REPONAME --tags
git merge --allow-unrelated-histories $REPONAME/master -m"merge"
git remote remove $REPONAME
git push
cd ..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment