Skip to content

Instantly share code, notes, and snippets.

@skseth
Last active January 27, 2023 10:29
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 skseth/b56ee18f6d4a225ca4ff519bbf124a8e to your computer and use it in GitHub Desktop.
Save skseth/b56ee18f6d4a225ca4ff519bbf124a8e to your computer and use it in GitHub Desktop.
Merging repos into a monorepo
# SRC_REPO, TGT_REPO are relative to current directory
SRC_REPO=$1
TGT_REPO=$2
DIR_NAME=$3
BRANCH_NAME=$4
pushd $SRC_REPO
git filter-repo --to-subdirectory "$DIR_NAME" # replace w/ your dir name
popd
pushd $TGT_REPO
git config pull.rebase false # make sure this is set
git remote add $BRANCH_NAME ../$SRC_REPO #
git pull $BRANCH_NAME main --allow-unrelated-histories
git remote rm $BRANCH_NAME
You have to install git filter-repo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment