Skip to content

Instantly share code, notes, and snippets.

@krisselden
Last active March 26, 2019 21:00
Show Gist options
  • Save krisselden/73c2b8a320b498f38d3d03a3518267de to your computer and use it in GitHub Desktop.
Save krisselden/73c2b8a320b498f38d3d03a3518267de to your computer and use it in GitHub Desktop.
merge repo into monorepo at prefix with history
#!/usr/bin/env bash
remote_name=my-repo
[email protected]:my-org/my-repo.git
remote_branch=master
prefix=packages/$remote_name/ # trailing slash is important
git remote add $remote_name $remote_url
git fetch $remote_name
# create a merge commit with our side winning as the strategy but stop before committing it
git merge -s ours --allow-unrelated-histories --no-commit $remote_name/$remote_branch
# read tree into index with a prefix and update the working tree
git read-tree --prefix=$prefix -u $remote_name/$remote_branch
# now commit the merge commit
git commit -m "merge $remote_name/$remote_branch"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment