Skip to content

Instantly share code, notes, and snippets.

@JamieMason
Last active April 25, 2019 18:58
Show Gist options
  • Save JamieMason/b6e1401bd79e66274c768d1fe49d5bed to your computer and use it in GitHub Desktop.
Save JamieMason/b6e1401bd79e66274c768d1fe49d5bed to your computer and use it in GitHub Desktop.
Bash script to migrate multiple projects into one Lerna monorepo (https://lernajs.io)
#!/usr/bin/env bash
set -x
shopt -s extglob dotglob
cd "$HOME"
rm -rf "$HOME/TEMP_DIR"
mkdir "$HOME/TEMP_DIR"
cd "$HOME/TEMP_DIR"
git init
function clone_repo () {
git clone "https://github.com/some-username/$1.git"
cd "$1"
mkdir -p "packages/$1"
git mv !(packages|.git|..|.) packages
cd packages
git mv !("$1") "$1"
cd "$HOME/TEMP_DIR/$1"
git add . -A
git commit -m "Move source to packages/$1" -n
cd "$HOME/TEMP_DIR"
}
clone_repo "some-package-1"
clone_repo "some-package-2"
clone_repo "some-package-3"
cd "$HOME/TEMP_DIR"
mkdir lerna-monorepo
cd lerna-monorepo
git init
git pull $HOME/TEMP_DIR/some-package-1 master --allow-unrelated-histories -s resolve
git pull $HOME/TEMP_DIR/some-package-2 master --allow-unrelated-histories -s resolve
git pull $HOME/TEMP_DIR/some-package-3 master --allow-unrelated-histories -s resolve
set +x
shopt -u extglob dotglob
@pmaoui
Copy link

pmaoui commented Oct 8, 2018

Thank you for your script. It didn't work out of the box for me... I had to remove master for the git pull part:

git pull $HOME/TEMP_DIR/some-package-1 master --allow-unrelated-histories -s resolve

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment