{
    "content": [
        {
            "type": "text",
            "text": "# GIT-SUBTREE(1) (man)\n\n**Summary:** git-subtree - Merge subtrees together and split repository into subtrees\n\n**Synopsis:** git subtree [<options>] -P <prefix> add <local-commit>\ngit subtree [<options>] -P <prefix> add <repository> <remote-ref>\ngit subtree [<options>] -P <prefix> merge <local-commit>\ngit subtree [<options>] -P <prefix> split [<local-commit>]\ngit subtree [<options>] -P <prefix> pull <repository> <remote-ref>\ngit subtree [<options>] -P <prefix> push <repository> <refspec>\n\n## Section Outline\n\n- **NAME** (2 lines)\n- **SYNOPSIS** (11 lines)\n- **DESCRIPTION** (33 lines)\n- **COMMANDS** (42 lines)\n- **OPTIONS FOR ALL COMMANDS** (1 lines) — 10 subsections\n  - -q, --quiet (2 lines)\n  - -d, --debug (6 lines)\n  - OPTIONS FOR ADD AND MERGE (ALSO: PULL, SPLIT --REJOIN, AND P (4 lines)\n  - --squash (24 lines)\n  - OPTIONS FOR SPLIT (ALSO: PUSH) (18 lines)\n  - --ignore-joins (14 lines)\n  - --rejoin (15 lines)\n  - EXAMPLE 1. ADD COMMAND (15 lines)\n  - EXAMPLE 2. EXTRACT A SUBTREE USING COMMIT, MERGE AND PULL (54 lines)\n  - EXAMPLE 3. EXTRACT A SUBTREE USING A BRANCH (16 lines)\n- **AUTHOR** (2 lines)\n- **GIT** (2 lines)\n- **NOTES** (6 lines)\n\n## Full Content\n\n### NAME\n\ngit-subtree - Merge subtrees together and split repository into subtrees\n\n### SYNOPSIS\n\ngit subtree [<options>] -P <prefix> add <local-commit>\ngit subtree [<options>] -P <prefix> add <repository> <remote-ref>\ngit subtree [<options>] -P <prefix> merge <local-commit>\ngit subtree [<options>] -P <prefix> split [<local-commit>]\n\n\n\ngit subtree [<options>] -P <prefix> pull <repository> <remote-ref>\ngit subtree [<options>] -P <prefix> push <repository> <refspec>\n\n### DESCRIPTION\n\nSubtrees allow subprojects to be included within a subdirectory of the main project,\noptionally including the subproject’s entire history.\n\nFor example, you could include the source code for a library as a subdirectory of your\napplication.\n\nSubtrees are not to be confused with submodules, which are meant for the same task. Unlike\nsubmodules, subtrees do not need any special constructions (like .gitmodules files or\ngitlinks) be present in your repository, and do not force end-users of your repository to do\nanything special or to understand how subtrees work. A subtree is just a subdirectory that\ncan be committed to, branched, and merged along with your project in any way you want.\n\nThey are also not to be confused with using the subtree merge strategy. The main difference\nis that, besides merging the other project as a subdirectory, you can also extract the entire\nhistory of a subdirectory from your project and make it into a standalone project. Unlike the\nsubtree merge strategy you can alternate back and forth between these two operations. If the\nstandalone library gets updated, you can automatically merge the changes into your project;\nif you update the library inside your project, you can \"split\" the changes back out again and\nmerge them back into the library project.\n\nFor example, if a library you made for one application ends up being useful elsewhere, you\ncan extract its entire history and publish that as its own git repository, without\naccidentally intermingling the history of your application project.\n\nTip\nIn order to keep your commit messages clean, we recommend that people split their commits\nbetween the subtrees and the main project as much as possible. That is, if you make a\nchange that affects both the library and the main application, commit it in two pieces.\nThat way, when you split the library commits out later, their descriptions will still\nmake sense. But if this isn’t important to you, it’s not necessary. git subtree will\nsimply leave out the non-library-related parts of the commit when it splits it out into\nthe subproject later.\n\n### COMMANDS\n\nadd <local-commit>, add <repository> <remote-ref>\nCreate the <prefix> subtree by importing its contents from the given <local-commit> or\n<repository> and <remote-ref>. A new commit is created automatically, joining the\nimported project’s history with your own. With --squash, import only a single commit from\nthe subproject, rather than its entire history.\n\nmerge <local-commit>\nMerge recent changes up to <local-commit> into the <prefix> subtree. As with normal git\nmerge, this doesn’t remove your own local changes; it just merges those changes into the\nlatest <local-commit>. With --squash, create only one commit that contains all the\nchanges, rather than merging in the entire history.\n\nIf you use --squash, the merge direction doesn’t always have to be forward; you can use\nthis command to go back in time from v2.5 to v2.4, for example. If your merge introduces\na conflict, you can resolve it in the usual ways.\n\nsplit [<local-commit>]\nExtract a new, synthetic project history from the history of the <prefix> subtree of\n<local-commit>, or of HEAD if no <local-commit> is given. The new history includes only\nthe commits (including merges) that affected <prefix>, and each of those commits now has\nthe contents of <prefix> at the root of the project instead of in a subdirectory. Thus,\nthe newly created history is suitable for export as a separate git repository.\n\nAfter splitting successfully, a single commit ID is printed to stdout. This corresponds\nto the HEAD of the newly created tree, which you can manipulate however you want.\n\nRepeated splits of exactly the same history are guaranteed to be identical (i.e. to\nproduce the same commit IDs) as long as the settings passed to split (such as --annotate)\nare the same. Because of this, if you add new commits and then re-split, the new commits\nwill be attached as commits on top of the history you generated last time, so git merge\nand friends will work as expected.\n\npull <repository> <remote-ref>\nExactly like merge, but parallels git pull in that it fetches the given ref from the\nspecified remote repository.\n\npush <repository> [+][<local-commit>:]<remote-ref>\nDoes a split using the <prefix> subtree of <local-commit> and then does a git push to\npush the result to the <repository> and <remote-ref>. This can be used to push your\nsubtree to different branches of the remote repository. Just as with split, if no\n<local-commit> is given, then HEAD is used. The optional leading + is ignored.\n\n### OPTIONS FOR ALL COMMANDS\n\n#### -q, --quiet\n\nSuppress unnecessary output messages on stderr.\n\n#### -d, --debug\n\nProduce even more unnecessary output messages on stderr.\n\n-P <prefix>, --prefix=<prefix>\nSpecify the path in the repository to the subtree you want to manipulate. This option is\nmandatory for all commands.\n\n#### OPTIONS FOR ADD AND MERGE (ALSO: PULL, SPLIT --REJOIN, AND PUSH --REJOIN)\n\nThese options for add and merge may also be given to pull (which wraps merge), split --rejoin\n(which wraps either add or merge as appropriate), and push --rejoin (which wraps split\n--rejoin).\n\n#### --squash\n\nInstead of merging the entire history from the subtree project, produce only a single\ncommit that contains all the differences you want to merge, and then merge that new\ncommit into your project.\n\nUsing this option helps to reduce log clutter. People rarely want to see every change\nthat happened between v1.0 and v1.1 of the library they’re using, since none of the\ninterim versions were ever included in their application.\n\nUsing --squash also helps avoid problems when the same subproject is included multiple\ntimes in the same project, or is removed and then re-added. In such a case, it doesn’t\nmake sense to combine the histories anyway, since it’s unclear which part of the history\nbelongs to which subtree.\n\nFurthermore, with --squash, you can switch back and forth between different versions of a\nsubtree, rather than strictly forward.  git subtree merge --squash always adjusts the\nsubtree to match the exactly specified commit, even if getting to that commit would\nrequire undoing some changes that were added earlier.\n\nWhether or not you use --squash, changes made in your local repository remain intact and\ncan be later split and send upstream to the subproject.\n\n-m <message>, --message=<message>\nSpecify <message> as the commit message for the merge commit.\n\n#### OPTIONS FOR SPLIT (ALSO: PUSH)\n\nThese options for split may also be given to push (which wraps split).\n\n--annotate=<annotation>\nWhen generating synthetic history, add <annotation> as a prefix to each commit message.\nSince we’re creating new commits with the same commit message, but possibly different\ncontent, from the original commits, this can help to differentiate them and avoid\nconfusion.\n\nWhenever you split, you need to use the same <annotation>, or else you don’t have a\nguarantee that the new re-created history will be identical to the old one. That will\nprevent merging from working correctly. git subtree tries to make it work anyway,\nparticularly if you use --rejoin, but it may not always be effective.\n\n-b <branch>, --branch=<branch>\nAfter generating the synthetic history, create a new branch called <branch> that contains\nthe new history. This is suitable for immediate pushing upstream. <branch> must not\nalready exist.\n\n#### --ignore-joins\n\nIf you use --rejoin, git subtree attempts to optimize its history reconstruction to\ngenerate only the new commits since the last --rejoin.  --ignore-joins disables this\nbehavior, forcing it to regenerate the entire history. In a large project, this can take\na long time.\n\n--onto=<onto>\nIf your subtree was originally imported using something other than git subtree, its\nhistory may not match what git subtree is expecting. In that case, you can specify the\ncommit ID <onto> that corresponds to the first revision of the subproject’s history that\nwas imported into your project, and git subtree will attempt to build its history from\nthere.\n\nIf you used git subtree add, you should never need this option.\n\n#### --rejoin\n\nAfter splitting, merge the newly created synthetic history back into your main project.\nThat way, future splits can search only the part of history that has been added since the\nmost recent --rejoin.\n\nIf your split commits end up merged into the upstream subproject, and then you want to\nget the latest upstream version, this will allow git’s merge algorithm to more\nintelligently avoid conflicts (since it knows these synthetic commits are already part of\nthe upstream repository).\n\nUnfortunately, using this option results in git log showing an extra copy of every new\ncommit that was created (the original, and the synthetic one).\n\nIf you do all your merges with --squash, make sure you also use --squash when you split\n--rejoin.\n\n#### EXAMPLE 1. ADD COMMAND\n\nLet’s assume that you have a local repository that you would like to add an external vendor\nlibrary to. In this case we will add the git-subtree repository as a subdirectory of your\nalready existing git-extensions repository in ~/git-extensions/:\n\n$ git subtree add --prefix=git-subtree --squash \\\ngit://github.com/apenwarr/git-subtree.git master\n\nmaster needs to be a valid remote ref and can be a different branch name\n\nYou can omit the --squash flag, but doing so will increase the number of commits that are\nincluded in your local repository.\n\nWe now have a ~/git-extensions/git-subtree directory containing code from the master branch\nof git://github.com/apenwarr/git-subtree.git in our git-extensions repository.\n\n#### EXAMPLE 2. EXTRACT A SUBTREE USING COMMIT, MERGE AND PULL\n\nLet’s use the repository for the git source code as an example. First, get your own copy of\nthe git.git repository:\n\n$ git clone git://git.kernel.org/pub/scm/git/git.git test-git\n$ cd test-git\n\ngitweb (commit 1130ef3) was merged into git as of commit 0a8f4f0, after which it was no\nlonger maintained separately. But imagine it had been maintained separately, and we wanted to\nextract git’s changes to gitweb since that time, to share with the upstream. You could do\nthis:\n\n$ git subtree split --prefix=gitweb --annotate='(split) ' \\\n0a8f4f0^.. --onto=1130ef3 --rejoin \\\n--branch gitweb-latest\n$ gitk gitweb-latest\n$ git push git@github.com:whatever/gitweb.git gitweb-latest:master\n\n(We use 0a8f4f0^.. because that means \"all the changes from 0a8f4f0 to the current version,\nincluding 0a8f4f0 itself.\")\n\nIf gitweb had originally been merged using git subtree add (or a previous split had already\nbeen done with --rejoin specified) then you can do all your splits without having to remember\nany weird commit IDs:\n\n$ git subtree split --prefix=gitweb --annotate='(split) ' --rejoin \\\n--branch gitweb-latest2\n\nAnd you can merge changes back in from the upstream project just as easily:\n\n$ git subtree pull --prefix=gitweb \\\ngit@github.com:whatever/gitweb.git master\n\nOr, using --squash, you can actually rewind to an earlier version of gitweb:\n\n$ git subtree merge --prefix=gitweb --squash gitweb-latest~10\n\nThen make some changes:\n\n$ date >gitweb/myfile\n$ git add gitweb/myfile\n$ git commit -m 'created myfile'\n\nAnd fast forward again:\n\n$ git subtree merge --prefix=gitweb --squash gitweb-latest\n\nAnd notice that your change is still intact:\n\n$ ls -l gitweb/myfile\n\nAnd you can split it out and look at your changes versus the standard gitweb:\n\ngit log gitweb-latest..$(git subtree split --prefix=gitweb)\n\n#### EXAMPLE 3. EXTRACT A SUBTREE USING A BRANCH\n\nSuppose you have a source directory with many files and subdirectories, and you want to\nextract the lib directory to its own git project. Here’s a short way to do it:\n\nFirst, make the new repository wherever you want:\n\n$ <go to the new location>\n$ git init --bare\n\nBack in your original directory:\n\n$ git subtree split --prefix=lib --annotate=\"(split)\" -b split\n\nThen push the new branch onto the new empty repository:\n\n$ git push <new-repo> split:master\n\n### AUTHOR\n\nWritten by Avery Pennarun <apenwarr@gmail.com[1]>\n\n### GIT\n\nPart of the git(1) suite\n\n### NOTES\n\n1. apenwarr@gmail.com\nmailto:apenwarr@gmail.com\n\n\n\n[FIXME: source]                              02/26/2026                               GIT-SUBTREE(1)\n\n"
        }
    ],
    "structuredContent": {
        "command": "GIT-SUBTREE",
        "section": "1",
        "mode": "man",
        "summary": "git-subtree - Merge subtrees together and split repository into subtrees",
        "synopsis": "git subtree [<options>] -P <prefix> add <local-commit>\ngit subtree [<options>] -P <prefix> add <repository> <remote-ref>\ngit subtree [<options>] -P <prefix> merge <local-commit>\ngit subtree [<options>] -P <prefix> split [<local-commit>]\ngit subtree [<options>] -P <prefix> pull <repository> <remote-ref>\ngit subtree [<options>] -P <prefix> push <repository> <refspec>",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [
            {
                "flag": "-q",
                "long": "--quiet",
                "arg": null,
                "description": "Suppress unnecessary output messages on stderr."
            },
            {
                "flag": "-d",
                "long": "--debug",
                "arg": null,
                "description": "Produce even more unnecessary output messages on stderr. -P <prefix>, --prefix=<prefix> Specify the path in the repository to the subtree you want to manipulate. This option is mandatory for all commands."
            },
            {
                "flag": "",
                "long": "--squash",
                "arg": null,
                "description": "Instead of merging the entire history from the subtree project, produce only a single commit that contains all the differences you want to merge, and then merge that new commit into your project. Using this option helps to reduce log clutter. People rarely want to see every change that happened between v1.0 and v1.1 of the library they’re using, since none of the interim versions were ever included in their application. Using --squash also helps avoid problems when the same subproject is included multiple times in the same project, or is removed and then re-added. In such a case, it doesn’t make sense to combine the histories anyway, since it’s unclear which part of the history belongs to which subtree. Furthermore, with --squash, you can switch back and forth between different versions of a subtree, rather than strictly forward. git subtree merge --squash always adjusts the subtree to match the exactly specified commit, even if getting to that commit would require undoing some changes that were added earlier. Whether or not you use --squash, changes made in your local repository remain intact and can be later split and send upstream to the subproject. -m <message>, --message=<message> Specify <message> as the commit message for the merge commit."
            },
            {
                "flag": "",
                "long": "--ignore-joins",
                "arg": null,
                "description": "If you use --rejoin, git subtree attempts to optimize its history reconstruction to generate only the new commits since the last --rejoin. --ignore-joins disables this behavior, forcing it to regenerate the entire history. In a large project, this can take a long time. --onto=<onto> If your subtree was originally imported using something other than git subtree, its history may not match what git subtree is expecting. In that case, you can specify the commit ID <onto> that corresponds to the first revision of the subproject’s history that was imported into your project, and git subtree will attempt to build its history from there. If you used git subtree add, you should never need this option."
            },
            {
                "flag": "",
                "long": "--rejoin",
                "arg": null,
                "description": "After splitting, merge the newly created synthetic history back into your main project. That way, future splits can search only the part of history that has been added since the most recent --rejoin. If your split commits end up merged into the upstream subproject, and then you want to get the latest upstream version, this will allow git’s merge algorithm to more intelligently avoid conflicts (since it knows these synthetic commits are already part of the upstream repository). Unfortunately, using this option results in git log showing an extra copy of every new commit that was created (the original, and the synthetic one). If you do all your merges with --squash, make sure you also use --squash when you split --rejoin."
            }
        ],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 11,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 33,
                "subsections": []
            },
            {
                "name": "COMMANDS",
                "lines": 42,
                "subsections": []
            },
            {
                "name": "OPTIONS FOR ALL COMMANDS",
                "lines": 1,
                "subsections": [
                    {
                        "name": "-q, --quiet",
                        "lines": 2,
                        "flag": "-q",
                        "long": "--quiet"
                    },
                    {
                        "name": "-d, --debug",
                        "lines": 6,
                        "flag": "-d",
                        "long": "--debug"
                    },
                    {
                        "name": "OPTIONS FOR ADD AND MERGE (ALSO: PULL, SPLIT --REJOIN, AND PUSH --REJOIN)",
                        "lines": 4
                    },
                    {
                        "name": "--squash",
                        "lines": 24,
                        "long": "--squash"
                    },
                    {
                        "name": "OPTIONS FOR SPLIT (ALSO: PUSH)",
                        "lines": 18
                    },
                    {
                        "name": "--ignore-joins",
                        "lines": 14,
                        "long": "--ignore-joins"
                    },
                    {
                        "name": "--rejoin",
                        "lines": 15,
                        "long": "--rejoin"
                    },
                    {
                        "name": "EXAMPLE 1. ADD COMMAND",
                        "lines": 15
                    },
                    {
                        "name": "EXAMPLE 2. EXTRACT A SUBTREE USING COMMIT, MERGE AND PULL",
                        "lines": 54
                    },
                    {
                        "name": "EXAMPLE 3. EXTRACT A SUBTREE USING A BRANCH",
                        "lines": 16
                    }
                ]
            },
            {
                "name": "AUTHOR",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "GIT",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "NOTES",
                "lines": 6,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "git-subtree - Merge subtrees together and split repository into subtrees\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "git subtree [<options>] -P <prefix> add <local-commit>\ngit subtree [<options>] -P <prefix> add <repository> <remote-ref>\ngit subtree [<options>] -P <prefix> merge <local-commit>\ngit subtree [<options>] -P <prefix> split [<local-commit>]\n\n\n\ngit subtree [<options>] -P <prefix> pull <repository> <remote-ref>\ngit subtree [<options>] -P <prefix> push <repository> <refspec>\n\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "Subtrees allow subprojects to be included within a subdirectory of the main project,\noptionally including the subproject’s entire history.\n\nFor example, you could include the source code for a library as a subdirectory of your\napplication.\n\nSubtrees are not to be confused with submodules, which are meant for the same task. Unlike\nsubmodules, subtrees do not need any special constructions (like .gitmodules files or\ngitlinks) be present in your repository, and do not force end-users of your repository to do\nanything special or to understand how subtrees work. A subtree is just a subdirectory that\ncan be committed to, branched, and merged along with your project in any way you want.\n\nThey are also not to be confused with using the subtree merge strategy. The main difference\nis that, besides merging the other project as a subdirectory, you can also extract the entire\nhistory of a subdirectory from your project and make it into a standalone project. Unlike the\nsubtree merge strategy you can alternate back and forth between these two operations. If the\nstandalone library gets updated, you can automatically merge the changes into your project;\nif you update the library inside your project, you can \"split\" the changes back out again and\nmerge them back into the library project.\n\nFor example, if a library you made for one application ends up being useful elsewhere, you\ncan extract its entire history and publish that as its own git repository, without\naccidentally intermingling the history of your application project.\n\nTip\nIn order to keep your commit messages clean, we recommend that people split their commits\nbetween the subtrees and the main project as much as possible. That is, if you make a\nchange that affects both the library and the main application, commit it in two pieces.\nThat way, when you split the library commits out later, their descriptions will still\nmake sense. But if this isn’t important to you, it’s not necessary. git subtree will\nsimply leave out the non-library-related parts of the commit when it splits it out into\nthe subproject later.\n",
                "subsections": []
            },
            "COMMANDS": {
                "content": "add <local-commit>, add <repository> <remote-ref>\nCreate the <prefix> subtree by importing its contents from the given <local-commit> or\n<repository> and <remote-ref>. A new commit is created automatically, joining the\nimported project’s history with your own. With --squash, import only a single commit from\nthe subproject, rather than its entire history.\n\nmerge <local-commit>\nMerge recent changes up to <local-commit> into the <prefix> subtree. As with normal git\nmerge, this doesn’t remove your own local changes; it just merges those changes into the\nlatest <local-commit>. With --squash, create only one commit that contains all the\nchanges, rather than merging in the entire history.\n\nIf you use --squash, the merge direction doesn’t always have to be forward; you can use\nthis command to go back in time from v2.5 to v2.4, for example. If your merge introduces\na conflict, you can resolve it in the usual ways.\n\nsplit [<local-commit>]\nExtract a new, synthetic project history from the history of the <prefix> subtree of\n<local-commit>, or of HEAD if no <local-commit> is given. The new history includes only\nthe commits (including merges) that affected <prefix>, and each of those commits now has\nthe contents of <prefix> at the root of the project instead of in a subdirectory. Thus,\nthe newly created history is suitable for export as a separate git repository.\n\nAfter splitting successfully, a single commit ID is printed to stdout. This corresponds\nto the HEAD of the newly created tree, which you can manipulate however you want.\n\nRepeated splits of exactly the same history are guaranteed to be identical (i.e. to\nproduce the same commit IDs) as long as the settings passed to split (such as --annotate)\nare the same. Because of this, if you add new commits and then re-split, the new commits\nwill be attached as commits on top of the history you generated last time, so git merge\nand friends will work as expected.\n\npull <repository> <remote-ref>\nExactly like merge, but parallels git pull in that it fetches the given ref from the\nspecified remote repository.\n\npush <repository> [+][<local-commit>:]<remote-ref>\nDoes a split using the <prefix> subtree of <local-commit> and then does a git push to\npush the result to the <repository> and <remote-ref>. This can be used to push your\nsubtree to different branches of the remote repository. Just as with split, if no\n<local-commit> is given, then HEAD is used. The optional leading + is ignored.\n",
                "subsections": []
            },
            "OPTIONS FOR ALL COMMANDS": {
                "content": "",
                "subsections": [
                    {
                        "name": "-q, --quiet",
                        "content": "Suppress unnecessary output messages on stderr.\n",
                        "flag": "-q",
                        "long": "--quiet"
                    },
                    {
                        "name": "-d, --debug",
                        "content": "Produce even more unnecessary output messages on stderr.\n\n-P <prefix>, --prefix=<prefix>\nSpecify the path in the repository to the subtree you want to manipulate. This option is\nmandatory for all commands.\n",
                        "flag": "-d",
                        "long": "--debug"
                    },
                    {
                        "name": "OPTIONS FOR ADD AND MERGE (ALSO: PULL, SPLIT --REJOIN, AND PUSH --REJOIN)",
                        "content": "These options for add and merge may also be given to pull (which wraps merge), split --rejoin\n(which wraps either add or merge as appropriate), and push --rejoin (which wraps split\n--rejoin).\n"
                    },
                    {
                        "name": "--squash",
                        "content": "Instead of merging the entire history from the subtree project, produce only a single\ncommit that contains all the differences you want to merge, and then merge that new\ncommit into your project.\n\nUsing this option helps to reduce log clutter. People rarely want to see every change\nthat happened between v1.0 and v1.1 of the library they’re using, since none of the\ninterim versions were ever included in their application.\n\nUsing --squash also helps avoid problems when the same subproject is included multiple\ntimes in the same project, or is removed and then re-added. In such a case, it doesn’t\nmake sense to combine the histories anyway, since it’s unclear which part of the history\nbelongs to which subtree.\n\nFurthermore, with --squash, you can switch back and forth between different versions of a\nsubtree, rather than strictly forward.  git subtree merge --squash always adjusts the\nsubtree to match the exactly specified commit, even if getting to that commit would\nrequire undoing some changes that were added earlier.\n\nWhether or not you use --squash, changes made in your local repository remain intact and\ncan be later split and send upstream to the subproject.\n\n-m <message>, --message=<message>\nSpecify <message> as the commit message for the merge commit.\n",
                        "long": "--squash"
                    },
                    {
                        "name": "OPTIONS FOR SPLIT (ALSO: PUSH)",
                        "content": "These options for split may also be given to push (which wraps split).\n\n--annotate=<annotation>\nWhen generating synthetic history, add <annotation> as a prefix to each commit message.\nSince we’re creating new commits with the same commit message, but possibly different\ncontent, from the original commits, this can help to differentiate them and avoid\nconfusion.\n\nWhenever you split, you need to use the same <annotation>, or else you don’t have a\nguarantee that the new re-created history will be identical to the old one. That will\nprevent merging from working correctly. git subtree tries to make it work anyway,\nparticularly if you use --rejoin, but it may not always be effective.\n\n-b <branch>, --branch=<branch>\nAfter generating the synthetic history, create a new branch called <branch> that contains\nthe new history. This is suitable for immediate pushing upstream. <branch> must not\nalready exist.\n"
                    },
                    {
                        "name": "--ignore-joins",
                        "content": "If you use --rejoin, git subtree attempts to optimize its history reconstruction to\ngenerate only the new commits since the last --rejoin.  --ignore-joins disables this\nbehavior, forcing it to regenerate the entire history. In a large project, this can take\na long time.\n\n--onto=<onto>\nIf your subtree was originally imported using something other than git subtree, its\nhistory may not match what git subtree is expecting. In that case, you can specify the\ncommit ID <onto> that corresponds to the first revision of the subproject’s history that\nwas imported into your project, and git subtree will attempt to build its history from\nthere.\n\nIf you used git subtree add, you should never need this option.\n",
                        "long": "--ignore-joins"
                    },
                    {
                        "name": "--rejoin",
                        "content": "After splitting, merge the newly created synthetic history back into your main project.\nThat way, future splits can search only the part of history that has been added since the\nmost recent --rejoin.\n\nIf your split commits end up merged into the upstream subproject, and then you want to\nget the latest upstream version, this will allow git’s merge algorithm to more\nintelligently avoid conflicts (since it knows these synthetic commits are already part of\nthe upstream repository).\n\nUnfortunately, using this option results in git log showing an extra copy of every new\ncommit that was created (the original, and the synthetic one).\n\nIf you do all your merges with --squash, make sure you also use --squash when you split\n--rejoin.\n",
                        "long": "--rejoin"
                    },
                    {
                        "name": "EXAMPLE 1. ADD COMMAND",
                        "content": "Let’s assume that you have a local repository that you would like to add an external vendor\nlibrary to. In this case we will add the git-subtree repository as a subdirectory of your\nalready existing git-extensions repository in ~/git-extensions/:\n\n$ git subtree add --prefix=git-subtree --squash \\\ngit://github.com/apenwarr/git-subtree.git master\n\nmaster needs to be a valid remote ref and can be a different branch name\n\nYou can omit the --squash flag, but doing so will increase the number of commits that are\nincluded in your local repository.\n\nWe now have a ~/git-extensions/git-subtree directory containing code from the master branch\nof git://github.com/apenwarr/git-subtree.git in our git-extensions repository.\n"
                    },
                    {
                        "name": "EXAMPLE 2. EXTRACT A SUBTREE USING COMMIT, MERGE AND PULL",
                        "content": "Let’s use the repository for the git source code as an example. First, get your own copy of\nthe git.git repository:\n\n$ git clone git://git.kernel.org/pub/scm/git/git.git test-git\n$ cd test-git\n\ngitweb (commit 1130ef3) was merged into git as of commit 0a8f4f0, after which it was no\nlonger maintained separately. But imagine it had been maintained separately, and we wanted to\nextract git’s changes to gitweb since that time, to share with the upstream. You could do\nthis:\n\n$ git subtree split --prefix=gitweb --annotate='(split) ' \\\n0a8f4f0^.. --onto=1130ef3 --rejoin \\\n--branch gitweb-latest\n$ gitk gitweb-latest\n$ git push git@github.com:whatever/gitweb.git gitweb-latest:master\n\n(We use 0a8f4f0^.. because that means \"all the changes from 0a8f4f0 to the current version,\nincluding 0a8f4f0 itself.\")\n\nIf gitweb had originally been merged using git subtree add (or a previous split had already\nbeen done with --rejoin specified) then you can do all your splits without having to remember\nany weird commit IDs:\n\n$ git subtree split --prefix=gitweb --annotate='(split) ' --rejoin \\\n--branch gitweb-latest2\n\nAnd you can merge changes back in from the upstream project just as easily:\n\n$ git subtree pull --prefix=gitweb \\\ngit@github.com:whatever/gitweb.git master\n\nOr, using --squash, you can actually rewind to an earlier version of gitweb:\n\n$ git subtree merge --prefix=gitweb --squash gitweb-latest~10\n\nThen make some changes:\n\n$ date >gitweb/myfile\n$ git add gitweb/myfile\n$ git commit -m 'created myfile'\n\nAnd fast forward again:\n\n$ git subtree merge --prefix=gitweb --squash gitweb-latest\n\nAnd notice that your change is still intact:\n\n$ ls -l gitweb/myfile\n\nAnd you can split it out and look at your changes versus the standard gitweb:\n\ngit log gitweb-latest..$(git subtree split --prefix=gitweb)\n"
                    },
                    {
                        "name": "EXAMPLE 3. EXTRACT A SUBTREE USING A BRANCH",
                        "content": "Suppose you have a source directory with many files and subdirectories, and you want to\nextract the lib directory to its own git project. Here’s a short way to do it:\n\nFirst, make the new repository wherever you want:\n\n$ <go to the new location>\n$ git init --bare\n\nBack in your original directory:\n\n$ git subtree split --prefix=lib --annotate=\"(split)\" -b split\n\nThen push the new branch onto the new empty repository:\n\n$ git push <new-repo> split:master\n"
                    }
                ]
            },
            "AUTHOR": {
                "content": "Written by Avery Pennarun <apenwarr@gmail.com[1]>\n",
                "subsections": []
            },
            "GIT": {
                "content": "Part of the git(1) suite\n",
                "subsections": []
            },
            "NOTES": {
                "content": "1. apenwarr@gmail.com\nmailto:apenwarr@gmail.com\n\n\n\n[FIXME: source]                              02/26/2026                               GIT-SUBTREE(1)",
                "subsections": []
            }
        }
    }
}