-
-
Save Dhaulagiri/aa383f5481872fc650a150ac7f3f56ce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script takes a remote repository and merges it into | |
# the current one as a subdirectory | |
set -e | |
# REPOS=('design-system-components' 'design-system-tokens' 'design-system-figma-scripting') | |
# REPOS=('flight') | |
REPOS=('design-system-tokens') | |
for repo in "${REPOS[@]}" | |
do | |
REPO_REMOTE="https://github.com/hashicorp/${repo}" | |
REPO_DIR_TMP="$(mktemp -d -t "${repo##*/}.XXXX")" | |
REPO_NAME=$repo | |
echo "REPO REMOTE: $REPO_REMOTE" | |
echo "REPO NAME: $REPO_NAME" | |
echo "REPO TMP DIR: $REPO_DIR_TMP" | |
echo | |
# clone other repo | |
git clone "$REPO_REMOTE" "$REPO_DIR_TMP" | |
# rewrite the entire history into sub-directory | |
export REPO_NAME | |
( | |
cd $REPO_DIR_TMP && | |
git filter-repo --to-subdirectory-filter "packages/" | |
) | |
# merge the rewritten repo | |
git remote add "$REPO_NAME" "$REPO_DIR_TMP" -f | |
git fetch "$REPO_NAME" | |
# if you're running an older version of git, remove --allow-unrelated-histories | |
git merge --allow-unrelated-histories "$REPO_NAME/main" -m "Merge ${REPO_NAME} into design system monorepo" | |
# loop through all remote branches and create local copies | |
for branch in $(git for-each-ref --format='%(refname:short)' refs/remotes/${REPO_NAME} --no-merged); do | |
git checkout -b "${branch}" "${branch}" | |
done | |
# return to main | |
git checkout main | |
# delete the rewritten repo | |
rm -rf "$REPO_DIR_TMP" | |
git remote rm "$REPO_NAME" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
git filter-repo
isn't a git command out of the box. Installbrew install git-filter-repo
via Homebrew re: https://superuser.com/a/1646987. Another reference: https://github.com/newren/git-filter-repo