{
    "content": [
        {
            "type": "text",
            "text": "# gitworkflows (man)\n\n## NAME\n\ngitworkflows - An overview of recommended workflows with Git\n\n## SYNOPSIS\n\ngit *\n\n## DESCRIPTION\n\nThis document attempts to write down and motivate some of the workflow elements used for\ngit.git itself. Many ideas apply in general, though the full workflow is rarely required for\nsmaller projects with fewer people involved.\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **SEPARATE CHANGES**\n- **MANAGING BRANCHES** (18 subsections)\n- **DISTRIBUTED WORKFLOWS** (11 subsections)\n- **SEE ALSO**\n- **GIT**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "gitworkflows",
        "section": "",
        "mode": "man",
        "summary": "gitworkflows - An overview of recommended workflows with Git",
        "synopsis": "git *",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [
            {
                "name": "gittutorial",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/gittutorial/7/json"
            },
            {
                "name": "git-push",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/git-push/1/json"
            },
            {
                "name": "git-pull",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/git-pull/1/json"
            },
            {
                "name": "git-merge",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/git-merge/1/json"
            },
            {
                "name": "git-rebase",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/git-rebase/1/json"
            },
            {
                "name": "git-format-patch",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/git-format-patch/1/json"
            },
            {
                "name": "git-send-email",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/git-send-email/1/json"
            },
            {
                "name": "git-am",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/git-am/1/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 8,
                "subsections": []
            },
            {
                "name": "SEPARATE CHANGES",
                "lines": 12,
                "subsections": []
            },
            {
                "name": "MANAGING BRANCHES",
                "lines": 16,
                "subsections": [
                    {
                        "name": "Graduation",
                        "lines": 20
                    },
                    {
                        "name": "Merging upwards",
                        "lines": 4
                    },
                    {
                        "name": "Example 1. Merge upwards",
                        "lines": 8
                    },
                    {
                        "name": "Topic branches",
                        "lines": 11
                    },
                    {
                        "name": "Example 2. Topic branches",
                        "lines": 24
                    },
                    {
                        "name": "Example 3. Merge to downstream only at well-defined points",
                        "lines": 9
                    },
                    {
                        "name": "Throw-away integration",
                        "lines": 7
                    },
                    {
                        "name": "Example 4. Throw-away integration branches",
                        "lines": 8
                    },
                    {
                        "name": "Branch management for a release",
                        "lines": 14
                    },
                    {
                        "name": "git log master..maint",
                        "lines": 6
                    },
                    {
                        "name": "Example 6. Release tagging",
                        "lines": 1
                    },
                    {
                        "name": "git tag -s -m \"Git X.Y.Z\" vX.Y.Z master",
                        "lines": 8
                    },
                    {
                        "name": "Maintenance branch management after a feature release",
                        "lines": 9
                    },
                    {
                        "name": "Example 7. Copy maint",
                        "lines": 1
                    },
                    {
                        "name": "git branch maint-X.Y.(Z-1) maint",
                        "lines": 3
                    },
                    {
                        "name": "Example 8. Update maint to new release",
                        "lines": 8
                    },
                    {
                        "name": "Branch management for next and seen after a feature release",
                        "lines": 3
                    },
                    {
                        "name": "Example 9. Rewind and rebuild next",
                        "lines": 21
                    }
                ]
            },
            {
                "name": "DISTRIBUTED WORKFLOWS",
                "lines": 12,
                "subsections": [
                    {
                        "name": "Merge workflow",
                        "lines": 17
                    },
                    {
                        "name": "Example 10. Push/pull: Publishing branches/topics",
                        "lines": 9
                    },
                    {
                        "name": "Example 11. Push/pull: Staying up to date",
                        "lines": 14
                    },
                    {
                        "name": "Example 12. Push/pull: Merging remote topics",
                        "lines": 1
                    },
                    {
                        "name": "git pull <URL> <branch>",
                        "lines": 5
                    },
                    {
                        "name": "Patch workflow",
                        "lines": 5
                    },
                    {
                        "name": "Example 13. format-patch/am: Publishing branches/topics",
                        "lines": 10
                    },
                    {
                        "name": "Example 14. format-patch/am: Keeping topics up to date",
                        "lines": 1
                    },
                    {
                        "name": "git pull --rebase <URL> <branch>",
                        "lines": 7
                    },
                    {
                        "name": "Example 15. format-patch/am: Importing patches",
                        "lines": 1
                    },
                    {
                        "name": "git am < patch",
                        "lines": 4
                    }
                ]
            },
            {
                "name": "SEE ALSO",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "GIT",
                "lines": 3,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "gitworkflows - An overview of recommended workflows with Git\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "git *\n\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "This document attempts to write down and motivate some of the workflow elements used for\ngit.git itself. Many ideas apply in general, though the full workflow is rarely required for\nsmaller projects with fewer people involved.\n\nWe formulate a set of rules for quick reference, while the prose tries to motivate each of\nthem. Do not always take them literally; you should value good reasons for your actions\nhigher than manpages such as this one.\n",
                "subsections": []
            },
            "SEPARATE CHANGES": {
                "content": "As a general rule, you should try to split your changes into small logical steps, and commit\neach of them. They should be consistent, working independently of any later commits, pass the\ntest suite, etc. This makes the review process much easier, and the history much more useful\nfor later inspection and analysis, for example with git-blame(1) and git-bisect(1).\n\nTo achieve this, try to split your work into small steps from the very beginning. It is\nalways easier to squash a few commits together than to split one big commit into several.\nDon’t be afraid of making too small or imperfect steps along the way. You can always go back\nlater and edit the commits with git rebase --interactive before you publish them. You can use\ngit stash push --keep-index to run the test suite independent of other uncommitted changes;\nsee the EXAMPLES section of git-stash(1).\n",
                "subsections": []
            },
            "MANAGING BRANCHES": {
                "content": "There are two main tools that can be used to include changes from one branch on another: git-\nmerge(1) and git-cherry-pick(1).\n\nMerges have many advantages, so we try to solve as many problems as possible with merges\nalone. Cherry-picking is still occasionally useful; see \"Merging upwards\" below for an\nexample.\n\nMost importantly, merging works at the branch level, while cherry-picking works at the commit\nlevel. This means that a merge can carry over the changes from 1, 10, or 1000 commits with\nequal ease, which in turn means the workflow scales much better to a large number of\ncontributors (and contributions). Merges are also easier to understand because a merge commit\nis a \"promise\" that all changes from all its parents are now included.\n\nThere is a tradeoff of course: merges require a more careful branch management. The following\nsubsections discuss the important points.\n",
                "subsections": [
                    {
                        "name": "Graduation",
                        "content": "As a given feature goes from experimental to stable, it also \"graduates\" between the\ncorresponding branches of the software. git.git uses the following integration branches:\n\n•   maint tracks the commits that should go into the next \"maintenance release\", i.e., update\nof the last released stable version;\n\n•   master tracks the commits that should go into the next release;\n\n•   next is intended as a testing branch for topics being tested for stability for master.\n\nThere is a fourth official branch that is used slightly differently:\n\n•   seen (patches seen by the maintainer) is an integration branch for things that are not\nquite ready for inclusion yet (see \"Integration Branches\" below).\n\nEach of the four branches is usually a direct descendant of the one above it.\n\nConceptually, the feature enters at an unstable branch (usually next or seen), and\n\"graduates\" to master for the next release once it is considered stable enough.\n"
                    },
                    {
                        "name": "Merging upwards",
                        "content": "The \"downwards graduation\" discussed above cannot be done by actually merging downwards,\nhowever, since that would merge all changes on the unstable branch into the stable one. Hence\nthe following:\n"
                    },
                    {
                        "name": "Example 1. Merge upwards",
                        "content": "Always commit your fixes to the oldest supported branch that requires them. Then\n(periodically) merge the integration branches upwards into each other.\n\nThis gives a very controlled flow of fixes. If you notice that you have applied a fix to e.g.\nmaster that is also required in maint, you will need to cherry-pick it (using git-cherry-\npick(1)) downwards. This will happen a few times and is nothing to worry about unless you do\nit very frequently.\n"
                    },
                    {
                        "name": "Topic branches",
                        "content": "Any nontrivial feature will require several patches to implement, and may get extra bugfixes\nor improvements during its lifetime.\n\nCommitting everything directly on the integration branches leads to many problems: Bad\ncommits cannot be undone, so they must be reverted one by one, which creates confusing\nhistories and further error potential when you forget to revert part of a group of changes.\nWorking in parallel mixes up the changes, creating further confusion.\n\nUse of \"topic branches\" solves these problems. The name is pretty self explanatory, with a\ncaveat that comes from the \"merge upwards\" rule above:\n"
                    },
                    {
                        "name": "Example 2. Topic branches",
                        "content": "Make a side branch for every topic (feature, bugfix, ...). Fork it off at the oldest\nintegration branch that you will eventually want to merge it into.\n\nMany things can then be done very naturally:\n\n•   To get the feature/bugfix into an integration branch, simply merge it. If the topic has\nevolved further in the meantime, merge again. (Note that you do not necessarily have to\nmerge it to the oldest integration branch first. For example, you can first merge a\nbugfix to next, give it some testing time, and merge to maint when you know it is\nstable.)\n\n•   If you find you need new features from the branch other to continue working on your\ntopic, merge other to topic. (However, do not do this \"just habitually\", see below.)\n\n•   If you find you forked off the wrong branch and want to move it \"back in time\", use git-\nrebase(1).\n\nNote that the last point clashes with the other two: a topic that has been merged elsewhere\nshould not be rebased. See the section on RECOVERING FROM UPSTREAM REBASE in git-rebase(1).\n\nWe should point out that \"habitually\" (regularly for no real reason) merging an integration\nbranch into your topics — and by extension, merging anything upstream into anything\ndownstream on a regular basis — is frowned upon:\n"
                    },
                    {
                        "name": "Example 3. Merge to downstream only at well-defined points",
                        "content": "Do not merge to downstream except with a good reason: upstream API changes affect your\nbranch; your branch no longer merges to upstream cleanly; etc.\n\nOtherwise, the topic that was merged to suddenly contains more than a single (well-separated)\nchange. The many resulting small merges will greatly clutter up history. Anyone who later\ninvestigates the history of a file will have to find out whether that merge affected the\ntopic in development. An upstream might even inadvertently be merged into a \"more stable\"\nbranch. And so on.\n"
                    },
                    {
                        "name": "Throw-away integration",
                        "content": "If you followed the last paragraph, you will now have many small topic branches, and\noccasionally wonder how they interact. Perhaps the result of merging them does not even work?\nBut on the other hand, we want to avoid merging them anywhere \"stable\" because such merges\ncannot easily be undone.\n\nThe solution, of course, is to make a merge that we can undo: merge into a throw-away branch.\n"
                    },
                    {
                        "name": "Example 4. Throw-away integration branches",
                        "content": "To test the interaction of several topics, merge them into a throw-away branch. You must\nnever base any work on such a branch!\n\nIf you make it (very) clear that this branch is going to be deleted right after the testing,\nyou can even publish this branch, for example to give the testers a chance to work with it,\nor other developers a chance to see if their in-progress work will be compatible. git.git has\nsuch an official throw-away integration branch called seen.\n"
                    },
                    {
                        "name": "Branch management for a release",
                        "content": "Assuming you are using the merge approach discussed above, when you are releasing your\nproject you will need to do some additional branch management work.\n\nA feature release is created from the master branch, since master tracks the commits that\nshould go into the next feature release.\n\nThe master branch is supposed to be a superset of maint. If this condition does not hold,\nthen maint contains some commits that are not included on master. The fixes represented by\nthose commits will therefore not be included in your feature release.\n\nTo verify that master is indeed a superset of maint, use git log:\n\nExample 5. Verify master is a superset of maint\n"
                    },
                    {
                        "name": "git log master..maint",
                        "content": "This command should not list any commits. Otherwise, check out master and merge maint into\nit.\n\nNow you can proceed with the creation of the feature release. Apply a tag to the tip of\nmaster indicating the release version:\n"
                    },
                    {
                        "name": "Example 6. Release tagging",
                        "content": ""
                    },
                    {
                        "name": "git tag -s -m \"Git X.Y.Z\" vX.Y.Z master",
                        "content": "You need to push the new tag to a public Git server (see \"DISTRIBUTED WORKFLOWS\" below). This\nmakes the tag available to others tracking your project. The push could also trigger a\npost-update hook to perform release-related items such as building release tarballs and\npreformatted documentation pages.\n\nSimilarly, for a maintenance release, maint is tracking the commits to be released.\nTherefore, in the steps above simply tag and push maint rather than master.\n"
                    },
                    {
                        "name": "Maintenance branch management after a feature release",
                        "content": "After a feature release, you need to manage your maintenance branches.\n\nFirst, if you wish to continue to release maintenance fixes for the feature release made\nbefore the recent one, then you must create another branch to track commits for that previous\nrelease.\n\nTo do this, the current maintenance branch is copied to another branch named with the\nprevious release version number (e.g. maint-X.Y.(Z-1) where X.Y.Z is the current release).\n"
                    },
                    {
                        "name": "Example 7. Copy maint",
                        "content": ""
                    },
                    {
                        "name": "git branch maint-X.Y.(Z-1) maint",
                        "content": "The maint branch should now be fast-forwarded to the newly released code so that maintenance\nfixes can be tracked for the current release:\n"
                    },
                    {
                        "name": "Example 8. Update maint to new release",
                        "content": "•   git checkout maint\n\n•   git merge --ff-only master\n\nIf the merge fails because it is not a fast-forward, then it is possible some fixes on maint\nwere missed in the feature release. This will not happen if the content of the branches was\nverified as described in the previous section.\n"
                    },
                    {
                        "name": "Branch management for next and seen after a feature release",
                        "content": "After a feature release, the integration branch next may optionally be rewound and rebuilt\nfrom the tip of master using the surviving topics on next:\n"
                    },
                    {
                        "name": "Example 9. Rewind and rebuild next",
                        "content": "•   git switch -C next master\n\n•   git merge ai/topicinnext1\n\n•   git merge ai/topicinnext2\n\n•   ...\n\nThe advantage of doing this is that the history of next will be clean. For example, some\ntopics merged into next may have initially looked promising, but were later found to be\nundesirable or premature. In such a case, the topic is reverted out of next but the fact\nremains in the history that it was once merged and reverted. By recreating next, you give\nanother incarnation of such topics a clean slate to retry, and a feature release is a good\npoint in history to do so.\n\nIf you do this, then you should make a public announcement indicating that next was rewound\nand rebuilt.\n\nThe same rewind and rebuild process may be followed for seen. A public announcement is not\nnecessary since seen is a throw-away branch, as described above.\n"
                    }
                ]
            },
            "DISTRIBUTED WORKFLOWS": {
                "content": "After the last section, you should know how to manage topics. In general, you will not be the\nonly person working on the project, so you will have to share your work.\n\nRoughly speaking, there are two important workflows: merge and patch. The important\ndifference is that the merge workflow can propagate full history, including merges, while\npatches cannot. Both workflows can be used in parallel: in git.git, only subsystem\nmaintainers use the merge workflow, while everyone else sends patches.\n\nNote that the maintainer(s) may impose restrictions, such as \"Signed-off-by\" requirements,\nthat all commits/patches submitted for inclusion must adhere to. Consult your project’s\ndocumentation for more information.\n",
                "subsections": [
                    {
                        "name": "Merge workflow",
                        "content": "The merge workflow works by copying branches between upstream and downstream. Upstream can\nmerge contributions into the official history; downstream base their work on the official\nhistory.\n\nThere are three main tools that can be used for this:\n\n•   git-push(1) copies your branches to a remote repository, usually to one that can be read\nby all involved parties;\n\n•   git-fetch(1) that copies remote branches to your repository; and\n\n•   git-pull(1) that does fetch and merge in one go.\n\nNote the last point. Do not use git pull unless you actually want to merge the remote branch.\n\nGetting changes out is easy:\n"
                    },
                    {
                        "name": "Example 10. Push/pull: Publishing branches/topics",
                        "content": "git push <remote> <branch> and tell everyone where they can fetch from.\n\nYou will still have to tell people by other means, such as mail. (Git provides the git-\nrequest-pull(1) to send preformatted pull requests to upstream maintainers to simplify this\ntask.)\n\nIf you just want to get the newest copies of the integration branches, staying up to date is\neasy too:\n"
                    },
                    {
                        "name": "Example 11. Push/pull: Staying up to date",
                        "content": "Use git fetch <remote> or git remote update to stay up to date.\n\nThen simply fork your topic branches from the stable remotes as explained earlier.\n\nIf you are a maintainer and would like to merge other people’s topic branches to the\nintegration branches, they will typically send a request to do so by mail. Such a request\nlooks like\n\nPlease pull from\n<URL> <branch>\n\n\nIn that case, git pull can do the fetch and merge in one go, as follows.\n"
                    },
                    {
                        "name": "Example 12. Push/pull: Merging remote topics",
                        "content": ""
                    },
                    {
                        "name": "git pull <URL> <branch>",
                        "content": "Occasionally, the maintainer may get merge conflicts when they try to pull changes from\ndownstream. In this case, they can ask downstream to do the merge and resolve the conflicts\nthemselves (perhaps they will know better how to resolve them). It is one of the rare cases\nwhere downstream should merge from upstream.\n"
                    },
                    {
                        "name": "Patch workflow",
                        "content": "If you are a contributor that sends changes upstream in the form of emails, you should use\ntopic branches as usual (see above). Then use git-format-patch(1) to generate the\ncorresponding emails (highly recommended over manually formatting them because it makes the\nmaintainer’s life easier).\n"
                    },
                    {
                        "name": "Example 13. format-patch/am: Publishing branches/topics",
                        "content": "•   git format-patch -M upstream..topic to turn them into preformatted patch files\n\n•   git send-email --to=<recipient> <patches>\n\nSee the git-format-patch(1) and git-send-email(1) manpages for further usage notes.\n\nIf the maintainer tells you that your patch no longer applies to the current upstream, you\nwill have to rebase your topic (you cannot use a merge because you cannot format-patch\nmerges):\n"
                    },
                    {
                        "name": "Example 14. format-patch/am: Keeping topics up to date",
                        "content": ""
                    },
                    {
                        "name": "git pull --rebase <URL> <branch>",
                        "content": "You can then fix the conflicts during the rebase. Presumably you have not published your\ntopic other than by mail, so rebasing it is not a problem.\n\nIf you receive such a patch series (as maintainer, or perhaps as a reader of the mailing list\nit was sent to), save the mails to files, create a new topic branch and use git am to import\nthe commits:\n"
                    },
                    {
                        "name": "Example 15. format-patch/am: Importing patches",
                        "content": ""
                    },
                    {
                        "name": "git am < patch",
                        "content": "One feature worth pointing out is the three-way merge, which can help if you get conflicts:\ngit am -3 will use index information contained in patches to figure out the merge base. See\ngit-am(1) for other options.\n"
                    }
                ]
            },
            "SEE ALSO": {
                "content": "gittutorial(7), git-push(1), git-pull(1), git-merge(1), git-rebase(1), git-format-patch(1),\ngit-send-email(1), git-am(1)\n",
                "subsections": []
            },
            "GIT": {
                "content": "Part of the git(1) suite\n\nGit 2.43.0                                   07/02/2025                              GITWORKFLOWS(7)",
                "subsections": []
            }
        }
    }
}