Skip to content

Instantly share code, notes, and snippets.

@zephraph
Created June 19, 2024 14:47
Show Gist options
  • Save zephraph/692f4adb55d326841146c8b76d36e080 to your computer and use it in GitHub Desktop.
Save zephraph/692f4adb55d326841146c8b76d36e080 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -euo pipefail
FROM=$1
TO=$2
NEW_NAME=${3:-$FROM}
cd "$FROM"
FROM=$(pwd)
# Uses https://github.com/newren/git-filter-repo
git filter-repo --to-subdirectory-filter "$NEW_NAME/"
cd "../$TO"
git remote add "$NEW_NAME" "$FROM"
git fetch "$NEW_NAME"
git checkout master
git merge --allow-unrelated-histories "$NEW_NAME"/main
git remote remove "$NEW_NAME"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment