Forrest logo
back to the git tool

git-subtree:tldr:6ae06

git-subtree: Extract a new project history from the history of a subtree.
$ git subtree split --prefix=${path-to-directory-} ${repository_url} -b ${branch_name}
try on your machine

The git subtree split command is used to extract a subdirectory from a repository and create a new repository with only that subdirectory's history, keeping both repositories connected.

Here is a breakdown of the command you provided:

  • git subtree split: This is the main command that extracts the subdirectory and creates a new repository.
  • --prefix=${path-to-directory-}: This option specifies the subdirectory path within the original repository that you want to extract. Replace ${path-to-directory-} with the actual path to the desired subdirectory.
  • ${repository_url}: This is the URL or path of the original repository from where you want to extract the subdirectory. It can be a remote repository URL or a local path.
  • -b ${branch_name}: This option is used to specify the name of the new branch that will be created in the newly created repository. Replace ${branch_name} with the desired name for the branch.

Overall, this command will create a new repository with only the specified subdirectory and its history, preserving the connection to the original repository.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the git tool