Skip to content

Instantly share code, notes, and snippets.

@umjammer
Last active February 5, 2024 23:56
Show Gist options
  • Save umjammer/a43ef2cb4de91852e2075b095405f3f9 to your computer and use it in GitHub Desktop.
Save umjammer/a43ef2cb4de91852e2075b095405f3f9 to your computer and use it in GitHub Desktop.
[git] move subtree inter projects

Git move subtree inter projects

  • at repo-1
cd repo-1
git subtree split -P dir-to-move -b <split>
  • at repo-2
cd repo-2
git checkout --orphan <temp>                    # Create a branch with no history
git pull <path-to-repo-1.git> <split>           # Pull the commits from the subtree
git checkout <branch>                           # Go back to the original branch (DONT use 'switch')
git merge --allow-unrelated-histories <temp>    # Merge the unrelated commits back
git branch -d <temp>                            # Delete the temporary branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment