Skip to main content

git subtree origin desc and manul

· One min read
Spark light

git subtree is powerful, but it document is not easy find by search engine. if search git subtree you got many article but not the origin doc.

so may be search by: git subtree txt

here is core desc of git subtree documentaion:

git split

    Extract a new, synthetic project history from the
history of the <prefix> subtree of <local-commit>, or of
HEAD if no <local-commit> is given. The new history
includes only the commits (including merges) that
affected <prefix>, and each of those commits now has the
contents of <prefix> at the root of the project instead
of in a subdirectory. Thus, the newly created history
is suitable for export as a separate git repository.

so git subtree core

 # split all commit relative with in /subdir into a new branch "tmpbranch"
git subtree split --prefix subdir -b tmpbranch
# push this branch to new repo
git push git@github.com/xxx/newrepo tmpbranch:main

one shortcut cmd do same of above

git subtree push --prefix subdir  git@github.com/xxx/newrepo main