Subtrees

Subtrees

Add a subtree

$ git subtree add --prefix=libs/utils <url> main --squash
$ git commit -m "Add utils subtree"

The --squash flag merges all upstream history into a single commit.

Pull updates from the upstream repository

$ git subtree pull --prefix=libs/utils <url> main --squash

Fetches upstream changes and merges them into the subtree directory.

Push changes back to the upstream repository

$ git subtree push --prefix=libs/utils <url> main

Extracts commits that touch the subtree directory and pushes them upstream.

Remove a subtree

$ git rm -r libs/utils
$ git commit -m "Remove utils subtree"

Unlike submodules, there is no metadata to clean up — just remove the directory.

On this page