{
    "mode": "man",
    "parameter": "GITCORE-TUTORIAL",
    "section": "7",
    "url": "https://www.chedong.com/phpMan.php/man/GITCORE-TUTORIAL/7/json",
    "generated": "2026-09-17T10:39:36Z",
    "synopsis": "git *",
    "sections": {
        "NAME": {
            "content": "gitcore-tutorial - A Git core tutorial for developers\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "git *\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This tutorial explains how to use the \"core\" Git commands to set up and work with a Git\nrepository.\n\nIf you just need to use Git as a revision control system you may prefer to start with \"A\nTutorial Introduction to Git\" (gittutorial(7)) or \u001b[34mthe Git User Manual[1].\n\nHowever, an understanding of these low-level tools can be helpful if you want to understand\nGit’s internals.\n\nThe core Git is often called \"plumbing\", with the prettier user interfaces on top of it\ncalled \"porcelain\". You may not want to use the plumbing directly very often, but it can be\ngood to know what the plumbing does when the porcelain isn’t flushing.\n\nBack when this document was originally written, many porcelain commands were shell scripts.\nFor simplicity, it still uses them as examples to illustrate how plumbing is fit together to\nform the porcelain commands. The source tree includes some of these scripts in\ncontrib/examples/ for reference. Although these are not implemented as shell scripts anymore,\nthe description of what the plumbing layer commands do is still valid.\n\nNote\n\nDeeper technical details are often marked as Notes, which you can skip on your first\nreading.\n",
            "subsections": []
        },
        "CREATING A GIT REPOSITORY": {
            "content": "Creating a new Git repository couldn’t be easier: all Git repositories start out empty, and\nthe only thing you need to do is find yourself a subdirectory that you want to use as a\nworking tree - either an empty one for a totally new project, or an existing working tree\nthat you want to import into Git.\n\nFor our first example, we’re going to start a totally new repository from scratch, with no\npre-existing files, and we’ll call it git-tutorial. To start up, create a subdirectory for\nit, change into that subdirectory, and initialize the Git infrastructure with git init:\n\n$ mkdir git-tutorial\n$ cd git-tutorial\n$ git init\n\n\nto which Git will reply\n\nInitialized empty Git repository in .git/\n\n\nwhich is just Git’s way of saying that you haven’t been doing anything strange, and that it\nwill have created a local .git directory setup for your new project. You will now have a .git\ndirectory, and you can inspect that with ls. For your new empty project, it should show you\nthree entries, among other things:\n\n•   a file called HEAD, that has ref: refs/heads/master in it. This is similar to a symbolic\nlink and points at refs/heads/master relative to the HEAD file.\n\nDon’t worry about the fact that the file that the HEAD link points to doesn’t even exist\nyet — you haven’t created the commit that will start your HEAD development branch yet.\n\n•   a subdirectory called objects, which will contain all the objects of your project. You\nshould never have any real reason to look at the objects directly, but you might want to\nknow that these objects are what contains all the real data in your repository.\n\n•   a subdirectory called refs, which contains references to objects.\n\nIn particular, the refs subdirectory will contain two other subdirectories, named heads and\ntags respectively. They do exactly what their names imply: they contain references to any\nnumber of different heads of development (aka branches), and to any tags that you have\ncreated to name specific versions in your repository.\n\nOne note: the special master head is the default branch, which is why the .git/HEAD file was\ncreated points to it even if it doesn’t yet exist. Basically, the HEAD link is supposed to\nalways point to the branch you are working on right now, and you always start out expecting\nto work on the master branch.\n\nHowever, this is only a convention, and you can name your branches anything you want, and\ndon’t have to ever even have a master branch. A number of the Git tools will assume that\n.git/HEAD is valid, though.\n\nNote\n\nAn object is identified by its 160-bit SHA-1 hash, aka object name, and a reference to an\nobject is always the 40-byte hex representation of that SHA-1 name. The files in the refs\nsubdirectory are expected to contain these hex references (usually with a final \\n at the\nend), and you should thus expect to see a number of 41-byte files containing these\nreferences in these refs subdirectories when you actually start populating your tree.\n\nNote\n\nAn advanced user may want to take a look at gitrepository-layout(5) after finishing this\ntutorial.\n\nYou have now created your first Git repository. Of course, since it’s empty, that’s not very\nuseful, so let’s start populating it with data.\n",
            "subsections": []
        },
        "POPULATING A GIT REPOSITORY": {
            "content": "We’ll keep this simple and stupid, so we’ll start off with populating a few trivial files\njust to get a feel for it.\n\nStart off with just creating any random files that you want to maintain in your Git\nrepository. We’ll start off with a few bad examples, just to get a feel for how this works:\n\n$ echo \"Hello World\" >hello\n$ echo \"Silly example\" >example\n\n\nyou have now created two files in your working tree (aka working directory), but to actually\ncheck in your hard work, you will have to go through two steps:\n\n•   fill in the index file (aka cache) with the information about your working tree state.\n\n•   commit that index file as an object.\n\nThe first step is trivial: when you want to tell Git about any changes to your working tree,\nyou use the git update-index program. That program normally just takes a list of filenames\nyou want to update, but to avoid trivial mistakes, it refuses to add new entries to the index\n(or remove existing ones) unless you explicitly tell it that you’re adding a new entry with\nthe --add flag (or removing an entry with the --remove) flag.\n\nSo to populate the index with the two files you just created, you can do\n\n$ git update-index --add hello example\n\n\nand you have now told Git to track those two files.\n\nIn fact, as you did that, if you now look into your object directory, you’ll notice that Git\nwill have added two new objects to the object database. If you did exactly the steps above,\nyou should now be able to do\n\n$ ls .git/objects/??/*\n\n\nand see two files:\n\n.git/objects/55/7db03de997c86a4a028e1ebd3a1ceb225be238\n.git/objects/f2/4c74a2e500f5ee1332c86b94199f52b1d1d962\n\n\nwhich correspond with the objects with names of 557db... and f24c7... respectively.\n\nIf you want to, you can use git cat-file to look at those objects, but you’ll have to use the\nobject name, not the filename of the object:\n\n$ git cat-file -t 557db03de997c86a4a028e1ebd3a1ceb225be238\n\n\nwhere the -t tells git cat-file to tell you what the \"type\" of the object is. Git will tell\nyou that you have a \"blob\" object (i.e., just a regular file), and you can see the contents\nwith\n\n$ git cat-file blob 557db03\n\n\nwhich will print out \"Hello World\". The object 557db03 is nothing more than the contents of\nyour file hello.\n\nNote\n\nDon’t confuse that object with the file hello itself. The object is literally just those\nspecific contents of the file, and however much you later change the contents in file\nhello, the object we just looked at will never change. Objects are immutable.\n\nNote\n\nThe second example demonstrates that you can abbreviate the object name to only the first\nseveral hexadecimal digits in most places.\n\nAnyway, as we mentioned previously, you normally never actually take a look at the objects\nthemselves, and typing long 40-character hex names is not something you’d normally want to\ndo. The above digression was just to show that git update-index did something magical, and\nactually saved away the contents of your files into the Git object database.\n\nUpdating the index did something else too: it created a .git/index file. This is the index\nthat describes your current working tree, and something you should be very aware of. Again,\nyou normally never worry about the index file itself, but you should be aware of the fact\nthat you have not actually really \"checked in\" your files into Git so far, you’ve only told\nGit about them.\n\nHowever, since Git knows about them, you can now start using some of the most basic Git\ncommands to manipulate the files or look at their status.\n\nIn particular, let’s not even check in the two files into Git yet, we’ll start off by adding\nanother line to hello first:\n\n$ echo \"It's a new day for git\" >>hello\n\n\nand you can now, since you told Git about the previous state of hello, ask Git what has\nchanged in the tree compared to your old index, using the git diff-files command:\n\n$ git diff-files\n\n\nOops. That wasn’t very readable. It just spit out its own internal version of a diff, but\nthat internal version really just tells you that it has noticed that \"hello\" has been\nmodified, and that the old object contents it had have been replaced with something else.\n\nTo make it readable, we can tell git diff-files to output the differences as a patch, using\nthe -p flag:\n\n$ git diff-files -p\ndiff --git a/hello b/hello\nindex 557db03..263414f 100644\n--- a/hello\n+++ b/hello\n@@ -1 +1,2 @@\nHello World\n+It's a new day for git\n\n\ni.e. the diff of the change we caused by adding another line to hello.\n\nIn other words, git diff-files always shows us the difference between what is recorded in the\nindex, and what is currently in the working tree. That’s very useful.\n\nA common shorthand for git diff-files -p is to just write git diff, which will do the same\nthing.\n\n$ git diff\ndiff --git a/hello b/hello\nindex 557db03..263414f 100644\n--- a/hello\n+++ b/hello\n@@ -1 +1,2 @@\nHello World\n+It's a new day for git\n\n",
            "subsections": []
        },
        "COMMITTING GIT STATE": {
            "content": "Now, we want to go to the next stage in Git, which is to take the files that Git knows about\nin the index, and commit them as a real tree. We do that in two phases: creating a tree\nobject, and committing that tree object as a commit object together with an explanation of\nwhat the tree was all about, along with information of how we came to that state.\n\nCreating a tree object is trivial, and is done with git write-tree. There are no options or\nother input: git write-tree will take the current index state, and write an object that\ndescribes that whole index. In other words, we’re now tying together all the different\nfilenames with their contents (and their permissions), and we’re creating the equivalent of a\nGit \"directory\" object:\n\n$ git write-tree\n\n\nand this will just output the name of the resulting tree, in this case (if you have done\nexactly as I’ve described) it should be\n\n8988da15d077d4829fc51d8544c097def6644dbb\n\n\nwhich is another incomprehensible object name. Again, if you want to, you can use git\ncat-file -t 8988d... to see that this time the object is not a \"blob\" object, but a \"tree\"\nobject (you can also use git cat-file to actually output the raw object contents, but you’ll\nsee mainly a binary mess, so that’s less interesting).\n\nHowever — normally you’d never use git write-tree on its own, because normally you always\ncommit a tree into a commit object using the git commit-tree command. In fact, it’s easier to\nnot actually use git write-tree on its own at all, but to just pass its result in as an\nargument to git commit-tree.\n\ngit commit-tree normally takes several arguments — it wants to know what the parent of a\ncommit was, but since this is the first commit ever in this new repository, and it has no\nparents, we only need to pass in the object name of the tree. However, git commit-tree also\nwants to get a commit message on its standard input, and it will write out the resulting\nobject name for the commit to its standard output.\n\nAnd this is where we create the .git/refs/heads/master file which is pointed at by HEAD. This\nfile is supposed to contain the reference to the top-of-tree of the master branch, and since\nthat’s exactly what git commit-tree spits out, we can do this all with a sequence of simple\nshell commands:\n\n$ tree=$(git write-tree)\n$ commit=$(echo 'Initial commit' | git commit-tree $tree)\n$ git update-ref HEAD $commit\n\n\nIn this case this creates a totally new commit that is not related to anything else. Normally\nyou do this only once for a project ever, and all later commits will be parented on top of an\nearlier commit.\n\nAgain, normally you’d never actually do this by hand. There is a helpful script called git\ncommit that will do all of this for you. So you could have just written git commit instead,\nand it would have done the above magic scripting for you.\n",
            "subsections": []
        },
        "MAKING A CHANGE": {
            "content": "Remember how we did the git update-index on file hello and then we changed hello afterward,\nand could compare the new state of hello with the state we saved in the index file?\n\nFurther, remember how I said that git write-tree writes the contents of the index file to the\ntree, and thus what we just committed was in fact the original contents of the file hello,\nnot the new ones. We did that on purpose, to show the difference between the index state, and\nthe state in the working tree, and how they don’t have to match, even when we commit things.\n\nAs before, if we do git diff-files -p in our git-tutorial project, we’ll still see the same\ndifference we saw last time: the index file hasn’t changed by the act of committing anything.\nHowever, now that we have committed something, we can also learn to use a new command: git\ndiff-index.\n\nUnlike git diff-files, which showed the difference between the index file and the working\ntree, git diff-index shows the differences between a committed tree and either the index file\nor the working tree. In other words, git diff-index wants a tree to be diffed against, and\nbefore we did the commit, we couldn’t do that, because we didn’t have anything to diff\nagainst.\n\nBut now we can do\n\n$ git diff-index -p HEAD\n\n\n(where -p has the same meaning as it did in git diff-files), and it will show us the same\ndifference, but for a totally different reason. Now we’re comparing the working tree not\nagainst the index file, but against the tree we just wrote. It just so happens that those two\nare obviously the same, so we get the same result.\n\nAgain, because this is a common operation, you can also just shorthand it with\n\n$ git diff HEAD\n\n\nwhich ends up doing the above for you.\n\nIn other words, git diff-index normally compares a tree against the working tree, but when\ngiven the --cached flag, it is told to instead compare against just the index cache contents,\nand ignore the current working tree state entirely. Since we just wrote the index file to\nHEAD, doing git diff-index --cached -p HEAD should thus return an empty set of differences,\nand that’s exactly what it does.\n\nNote\n\ngit diff-index really always uses the index for its comparisons, and saying that it\ncompares a tree against the working tree is thus not strictly accurate. In particular,\nthe list of files to compare (the \"meta-data\") always comes from the index file,\nregardless of whether the --cached flag is used or not. The --cached flag really only\ndetermines whether the file contents to be compared come from the working tree or not.\n\nThis is not hard to understand, as soon as you realize that Git simply never knows (or\ncares) about files that it is not told about explicitly. Git will never go looking for\nfiles to compare, it expects you to tell it what the files are, and that’s what the index\nis there for.\n\nHowever, our next step is to commit the change we did, and again, to understand what’s going\non, keep in mind the difference between \"working tree contents\", \"index file\" and \"committed\ntree\". We have changes in the working tree that we want to commit, and we always have to work\nthrough the index file, so the first thing we need to do is to update the index cache:\n\n$ git update-index hello\n\n\n(note how we didn’t need the --add flag this time, since Git knew about the file already).\n\nNote what happens to the different git diff-* versions here. After we’ve updated hello in the\nindex, git diff-files -p now shows no differences, but git diff-index -p HEAD still does show\nthat the current state is different from the state we committed. In fact, now git diff-index\nshows the same difference whether we use the --cached flag or not, since now the index is\ncoherent with the working tree.\n\nNow, since we’ve updated hello in the index, we can commit the new version. We could do it by\nwriting the tree by hand again, and committing the tree (this time we’d have to use the -p\nHEAD flag to tell commit that the HEAD was the parent of the new commit, and that this wasn’t\nan initial commit any more), but you’ve done that once already, so let’s just use the helpful\nscript this time:\n\n$ git commit\n\n\nwhich starts an editor for you to write the commit message and tells you a bit about what you\nhave done.\n\nWrite whatever message you want, and all the lines that start with # will be pruned out, and\nthe rest will be used as the commit message for the change. If you decide you don’t want to\ncommit anything after all at this point (you can continue to edit things and update the\nindex), you can just leave an empty message. Otherwise git commit will commit the change for\nyou.\n\nYou’ve now made your first real Git commit. And if you’re interested in looking at what git\ncommit really does, feel free to investigate: it’s a few very simple shell scripts to\ngenerate the helpful (?) commit message headers, and a few one-liners that actually do the\ncommit itself (git commit).\n",
            "subsections": []
        },
        "INSPECTING CHANGES": {
            "content": "While creating changes is useful, it’s even more useful if you can tell later what changed.\nThe most useful command for this is another of the diff family, namely git diff-tree.\n\ngit diff-tree can be given two arbitrary trees, and it will tell you the differences between\nthem. Perhaps even more commonly, though, you can give it just a single commit object, and it\nwill figure out the parent of that commit itself, and show the difference directly. Thus, to\nget the same diff that we’ve already seen several times, we can now do\n\n$ git diff-tree -p HEAD\n\n\n(again, -p means to show the difference as a human-readable patch), and it will show what the\nlast commit (in HEAD) actually changed.\n\nNote\n\nHere is an ASCII art by Jon Loeliger that illustrates how various diff-* commands compare\nthings.\n\ndiff-tree\n+----+\n|    |\n|    |\nV    V\n+-----------+\n| Object DB |\n|  Backing  |\n|   Store   |\n+-----------+\n^    ^\n|    |\n|    |  diff-index --cached\n|    |\ndiff-index  |    V\n|  +-----------+\n|  |   Index   |\n|  |  \"cache\"  |\n|  +-----------+\n|    ^\n|    |\n|    |  diff-files\n|    |\nV    V\n+-----------+\n|  Working  |\n| Directory |\n+-----------+\n\nMore interestingly, you can also give git diff-tree the --pretty flag, which tells it to also\nshow the commit message and author and date of the commit, and you can tell it to show a\nwhole series of diffs. Alternatively, you can tell it to be \"silent\", and not show the diffs\nat all, but just show the actual commit message.\n\nIn fact, together with the git rev-list program (which generates a list of revisions), git\ndiff-tree ends up being a veritable fount of changes. You can emulate git log, git log -p,\netc. with a trivial script that pipes the output of git rev-list to git diff-tree --stdin,\nwhich was exactly how early versions of git log were implemented.\n",
            "subsections": []
        },
        "TAGGING A VERSION": {
            "content": "In Git, there are two kinds of tags, a \"light\" one, and an \"annotated tag\".\n\nA \"light\" tag is technically nothing more than a branch, except we put it in the\n.git/refs/tags/ subdirectory instead of calling it a head. So the simplest form of tag\ninvolves nothing more than\n\n$ git tag my-first-tag\n\n\nwhich just writes the current HEAD into the .git/refs/tags/my-first-tag file, after which\npoint you can then use this symbolic name for that particular state. You can, for example, do\n\n$ git diff my-first-tag\n\n\nto diff your current state against that tag which at this point will obviously be an empty\ndiff, but if you continue to develop and commit stuff, you can use your tag as an\n\"anchor-point\" to see what has changed since you tagged it.\n\nAn \"annotated tag\" is actually a real Git object, and contains not only a pointer to the\nstate you want to tag, but also a small tag name and message, along with optionally a PGP\nsignature that says that yes, you really did that tag. You create these annotated tags with\neither the -a or -s flag to git tag:\n\n$ git tag -s <tagname>\n\n\nwhich will sign the current HEAD (but you can also give it another argument that specifies\nthe thing to tag, e.g., you could have tagged the current mybranch point by using git tag\n<tagname> mybranch).\n\nYou normally only do signed tags for major releases or things like that, while the\nlight-weight tags are useful for any marking you want to do — any time you decide that you\nwant to remember a certain point, just create a private tag for it, and you have a nice\nsymbolic name for the state at that point.\n",
            "subsections": []
        },
        "COPYING REPOSITORIES": {
            "content": "Git repositories are normally totally self-sufficient and relocatable. Unlike CVS, for\nexample, there is no separate notion of \"repository\" and \"working tree\". A Git repository\nnormally is the working tree, with the local Git information hidden in the .git subdirectory.\nThere is nothing else. What you see is what you got.\n\nNote\n\nYou can tell Git to split the Git internal information from the directory that it tracks,\nbut we’ll ignore that for now: it’s not how normal projects work, and it’s really only\nmeant for special uses. So the mental model of \"the Git information is always tied\ndirectly to the working tree that it describes\" may not be technically 100% accurate, but\nit’s a good model for all normal use.\n\nThis has two implications:\n\n•   if you grow bored with the tutorial repository you created (or you’ve made a mistake and\nwant to start all over), you can just do simple\n\n$ rm -rf git-tutorial\n\nand it will be gone. There’s no external repository, and there’s no history outside the\nproject you created.\n\n•   if you want to move or duplicate a Git repository, you can do so. There is git clone\ncommand, but if all you want to do is just to create a copy of your repository (with all\nthe full history that went along with it), you can do so with a regular cp -a\ngit-tutorial new-git-tutorial.\n\nNote that when you’ve moved or copied a Git repository, your Git index file (which caches\nvarious information, notably some of the \"stat\" information for the files involved) will\nlikely need to be refreshed. So after you do a cp -a to create a new copy, you’ll want to\ndo\n\n$ git update-index --refresh\n\nin the new repository to make sure that the index file is up to date.\n\nNote that the second point is true even across machines. You can duplicate a remote Git\nrepository with any regular copy mechanism, be it scp, rsync or wget.\n\nWhen copying a remote repository, you’ll want to at a minimum update the index cache when you\ndo this, and especially with other peoples' repositories you often want to make sure that the\nindex cache is in some known state (you don’t know what they’ve done and not yet checked in),\nso usually you’ll precede the git update-index with a\n\n$ git read-tree --reset HEAD\n$ git update-index --refresh\n\n\nwhich will force a total index re-build from the tree pointed to by HEAD. It resets the index\ncontents to HEAD, and then the git update-index makes sure to match up all index entries with\nthe checked-out files. If the original repository had uncommitted changes in its working\ntree, git update-index --refresh notices them and tells you they need to be updated.\n\nThe above can also be written as simply\n\n$ git reset\n\n\nand in fact a lot of the common Git command combinations can be scripted with the git xyz\ninterfaces. You can learn things by just looking at what the various git scripts do. For\nexample, git reset used to be the above two lines implemented in git reset, but some things\nlike git status and git commit are slightly more complex scripts around the basic Git\ncommands.\n\nMany (most?) public remote repositories will not contain any of the checked out files or even\nan index file, and will only contain the actual core Git files. Such a repository usually\ndoesn’t even have the .git subdirectory, but has all the Git files directly in the\nrepository.\n\nTo create your own local live copy of such a \"raw\" Git repository, you’d first create your\nown subdirectory for the project, and then copy the raw repository contents into the .git\ndirectory. For example, to create your own copy of the Git repository, you’d do the following\n\n$ mkdir my-git\n$ cd my-git\n$ rsync -rL rsync://rsync.kernel.org/pub/scm/git/git.git/ .git\n\n\nfollowed by\n\n$ git read-tree HEAD\n\n\nto populate the index. However, now you have populated the index, and you have all the Git\ninternal files, but you will notice that you don’t actually have any of the working tree\nfiles to work on. To get those, you’d check them out with\n\n$ git checkout-index -u -a\n\n\nwhere the -u flag means that you want the checkout to keep the index up to date (so that you\ndon’t have to refresh it afterward), and the -a flag means \"check out all files\" (if you have\na stale copy or an older version of a checked out tree you may also need to add the -f flag\nfirst, to tell git checkout-index to force overwriting of any old files).\n\nAgain, this can all be simplified with\n\n$ git clone git://git.kernel.org/pub/scm/git/git.git/ my-git\n$ cd my-git\n$ git checkout\n\n\nwhich will end up doing all of the above for you.\n\nYou have now successfully copied somebody else’s (mine) remote repository, and checked it\nout.\n",
            "subsections": []
        },
        "CREATING A NEW BRANCH": {
            "content": "Branches in Git are really nothing more than pointers into the Git object database from\nwithin the .git/refs/ subdirectory, and as we already discussed, the HEAD branch is nothing\nbut a symlink to one of these object pointers.\n\nYou can at any time create a new branch by just picking an arbitrary point in the project\nhistory, and just writing the SHA-1 name of that object into a file under .git/refs/heads/.\nYou can use any filename you want (and indeed, subdirectories), but the convention is that\nthe \"normal\" branch is called master. That’s just a convention, though, and nothing enforces\nit.\n\nTo show that as an example, let’s go back to the git-tutorial repository we used earlier, and\ncreate a branch in it. You do that by simply just saying that you want to check out a new\nbranch:\n\n$ git switch -c mybranch\n\n\nwill create a new branch based at the current HEAD position, and switch to it.\n\nNote\n\nIf you make the decision to start your new branch at some other point in the history than\nthe current HEAD, you can do so by just telling git switch what the base of the checkout\nwould be. In other words, if you have an earlier tag or branch, you’d just do\n\n$ git switch -c mybranch earlier-commit\n\n\nand it would create the new branch mybranch at the earlier commit, and check out the\nstate at that time.\n\nYou can always just jump back to your original master branch by doing\n\n$ git switch master\n\n\n(or any other branch-name, for that matter) and if you forget which branch you happen to be\non, a simple\n\n$ cat .git/HEAD\n\n\nwill tell you where it’s pointing. To get the list of branches you have, you can say\n\n$ git branch\n\n\nwhich used to be nothing more than a simple script around ls .git/refs/heads. There will be\nan asterisk in front of the branch you are currently on.\n\nSometimes you may wish to create a new branch without actually checking it out and switching\nto it. If so, just use the command\n\n$ git branch <branchname> [startingpoint]\n\n\nwhich will simply create the branch, but will not do anything further. You can then later —\nonce you decide that you want to actually develop on that branch — switch to that branch with\na regular git switch with the branchname as the argument.\n",
            "subsections": []
        },
        "MERGING TWO BRANCHES": {
            "content": "One of the ideas of having a branch is that you do some (possibly experimental) work in it,\nand eventually merge it back to the main branch. So assuming you created the above mybranch\nthat started out being the same as the original master branch, let’s make sure we’re in that\nbranch, and do some work there.\n\n$ git switch mybranch\n$ echo \"Work, work, work\" >>hello\n$ git commit -m \"Some work.\" -i hello\n\n\nHere, we just added another line to hello, and we used a shorthand for doing both git\nupdate-index hello and git commit by just giving the filename directly to git commit, with an",
            "subsections": [
                {
                    "name": "-i",
                    "content": "file so far when making the commit). The -m flag is to give the commit log message from the\ncommand line.\n\nNow, to make it a bit more interesting, let’s assume that somebody else does some work in the\noriginal branch, and simulate that by going back to the master branch, and editing the same\nfile differently there:\n\n$ git switch master\n\n\nHere, take a moment to look at the contents of hello, and notice how they don’t contain the\nwork we just did in mybranch — because that work hasn’t happened in the master branch at all.\nThen do\n\n$ echo \"Play, play, play\" >>hello\n$ echo \"Lots of fun\" >>example\n$ git commit -m \"Some fun.\" -i hello example\n\n\nsince the master branch is obviously in a much better mood.\n\nNow, you’ve got two branches, and you decide that you want to merge the work done. Before we\ndo that, let’s introduce a cool graphical tool that helps you view what’s going on:\n\n$ gitk --all\n\n\nwill show you graphically both of your branches (that’s what the --all means: normally it\nwill just show you your current HEAD) and their histories. You can also see exactly how they\ncame to be from a common source.\n\nAnyway, let’s exit gitk (^Q or the File menu), and decide that we want to merge the work we\ndid on the mybranch branch into the master branch (which is currently our HEAD too). To do\nthat, there’s a nice script called git merge, which wants to know which branches you want to\nresolve and what the merge is all about:\n\n$ git merge -m \"Merge work in mybranch\" mybranch\n\n\nwhere the first argument is going to be used as the commit message if the merge can be\nresolved automatically.\n\nNow, in this case we’ve intentionally created a situation where the merge will need to be\nfixed up by hand, though, so Git will do as much of it as it can automatically (which in this\ncase is just merge the example file, which had no differences in the mybranch branch), and\nsay:\n\nAuto-merging hello\nCONFLICT (content): Merge conflict in hello\nAutomatic merge failed; fix conflicts and then commit the result.\n\n\nIt tells you that it did an \"Automatic merge\", which failed due to conflicts in hello.\n\nNot to worry. It left the (trivial) conflict in hello in the same form you should already be\nwell used to if you’ve ever used CVS, so let’s just open hello in our editor (whatever that\nmay be), and fix it up somehow. I’d suggest just making it so that hello contains all four\nlines:\n\nHello World\nIt's a new day for git\nPlay, play, play\nWork, work, work\n\n\nand once you’re happy with your manual merge, just do a\n\n$ git commit -i hello\n\n\nwhich will very loudly warn you that you’re now committing a merge (which is correct, so\nnever mind), and you can write a small merge message about your adventures in git merge-land.\n\nAfter you’re done, start up gitk --all to see graphically what the history looks like. Notice\nthat mybranch still exists, and you can switch to it, and continue to work with it if you\nwant to. The mybranch branch will not contain the merge, but next time you merge it from the\nmaster branch, Git will know how you merged it, so you’ll not have to do that merge again.\n\nAnother useful tool, especially if you do not always work in X-Window environment, is git\nshow-branch.\n\n$ git show-branch --topo-order --more=1 master mybranch\n* [master] Merge work in mybranch\n! [mybranch] Some work.\n--\n-  [master] Merge work in mybranch\n*+ [mybranch] Some work.\n*  [master^] Some fun.\n\n\nThe first two lines indicate that it is showing the two branches with the titles of their\ntop-of-the-tree commits, you are currently on master branch (notice the asterisk *\ncharacter), and the first column for the later output lines is used to show commits contained\nin the master branch, and the second column for the mybranch branch. Three commits are shown\nalong with their titles. All of them have non blank characters in the first column (* shows\nan ordinary commit on the current branch, - is a merge commit), which means they are now part\nof the master branch. Only the \"Some work\" commit has the plus + character in the second\ncolumn, because mybranch has not been merged to incorporate these commits from the master\nbranch. The string inside brackets before the commit log message is a short name you can use\nto name the commit. In the above example, master and mybranch are branch heads. master^ is\nthe first parent of master branch head. Please see gitrevisions(7) if you want to see more\ncomplex cases.\n\nNote\n\nWithout the --more=1 option, git show-branch would not output the [master^] commit, as\n[mybranch] commit is a common ancestor of both master and mybranch tips. Please see git-\nshow-branch(1) for details.\n\nNote\n\nIf there were more commits on the master branch after the merge, the merge commit itself\nwould not be shown by git show-branch by default. You would need to provide --sparse\noption to make the merge commit visible in this case.\n\nNow, let’s pretend you are the one who did all the work in mybranch, and the fruit of your\nhard work has finally been merged to the master branch. Let’s go back to mybranch, and run\ngit merge to get the \"upstream changes\" back to your branch.\n\n$ git switch mybranch\n$ git merge -m \"Merge upstream changes.\" master\n\n\nThis outputs something like this (the actual commit object names would be different)\n\nUpdating from ae3a2da... to a80b4aa....\nFast-forward (no commit created; -m option ignored)\nexample | 1 +\nhello   | 1 +\n2 files changed, 2 insertions(+)\n\n\nBecause your branch did not contain anything more than what had already been merged into the\nmaster branch, the merge operation did not actually do a merge. Instead, it just updated the\ntop of the tree of your branch to that of the master branch. This is often called\nfast-forward merge.\n\nYou can run gitk --all again to see how the commit ancestry looks like, or run show-branch,\nwhich tells you this.\n\n$ git show-branch master mybranch\n! [master] Merge work in mybranch\n* [mybranch] Merge work in mybranch\n--\n-- [master] Merge work in mybranch\n\n",
                    "flag": "-i"
                }
            ]
        },
        "MERGING EXTERNAL WORK": {
            "content": "It’s usually much more common that you merge with somebody else than merging with your own\nbranches, so it’s worth pointing out that Git makes that very easy too, and in fact, it’s not\nthat different from doing a git merge. In fact, a remote merge ends up being nothing more\nthan \"fetch the work from a remote repository into a temporary tag\" followed by a git merge.\n\nFetching from a remote repository is done by, unsurprisingly, git fetch:\n\n$ git fetch <remote-repository>\n\n\nOne of the following transports can be used to name the repository to download from:\n\nSSH\nremote.machine:/path/to/repo.git/ or\n\nssh://remote.machine/path/to/repo.git/\n\nThis transport can be used for both uploading and downloading, and requires you to have a\nlog-in privilege over ssh to the remote machine. It finds out the set of objects the\nother side lacks by exchanging the head commits both ends have and transfers (close to)\nminimum set of objects. It is by far the most efficient way to exchange Git objects\nbetween repositories.\n\nLocal directory\n/path/to/repo.git/\n\nThis transport is the same as SSH transport but uses sh to run both ends on the local\nmachine instead of running other end on the remote machine via ssh.\n\nGit Native\ngit://remote.machine/path/to/repo.git/\n\nThis transport was designed for anonymous downloading. Like SSH transport, it finds out\nthe set of objects the downstream side lacks and transfers (close to) minimum set of\nobjects.\n\nHTTP(S)\nhttp://remote.machine/path/to/repo.git/\n\nDownloader from http and https URL first obtains the topmost commit object name from the\nremote site by looking at the specified refname under repo.git/refs/ directory, and then\ntries to obtain the commit object by downloading from repo.git/objects/xx/xxx...  using\nthe object name of that commit object. Then it reads the commit object to find out its\nparent commits and the associate tree object; it repeats this process until it gets all\nthe necessary objects. Because of this behavior, they are sometimes also called commit\nwalkers.\n\nThe commit walkers are sometimes also called dumb transports, because they do not require\nany Git aware smart server like Git Native transport does. Any stock HTTP server that\ndoes not even support directory index would suffice. But you must prepare your repository\nwith git update-server-info to help dumb transport downloaders.\n\nOnce you fetch from the remote repository, you merge that with your current branch.\n\nHowever — it’s such a common thing to fetch and then immediately merge, that it’s called git\npull, and you can simply do\n\n$ git pull <remote-repository>\n\n\nand optionally give a branch-name for the remote end as a second argument.\n\nNote\n\nYou could do without using any branches at all, by keeping as many local repositories as\nyou would like to have branches, and merging between them with git pull, just like you\nmerge between branches. The advantage of this approach is that it lets you keep a set of\nfiles for each branch checked out and you may find it easier to switch back and forth if\nyou juggle multiple lines of development simultaneously. Of course, you will pay the\nprice of more disk usage to hold multiple working trees, but disk space is cheap these\ndays.\n\nIt is likely that you will be pulling from the same remote repository from time to time. As a\nshort hand, you can store the remote repository URL in the local repository’s config file\nlike this:\n\n$ git config remote.linus.url http://www.kernel.org/pub/scm/git/git.git/\n\n\nand use the \"linus\" keyword with git pull instead of the full URL.\n\nExamples.\n\n1. git pull linus\n\n2. git pull linus tag v0.99.1\n\nthe above are equivalent to:\n\n1. git pull http://www.kernel.org/pub/scm/git/git.git/ HEAD\n\n2. git pull http://www.kernel.org/pub/scm/git/git.git/ tag v0.99.1\n\nHOW DOES THE MERGE WORK?\nWe said this tutorial shows what plumbing does to help you cope with the porcelain that isn’t\nflushing, but we so far did not talk about how the merge really works. If you are following\nthis tutorial the first time, I’d suggest to skip to \"Publishing your work\" section and come\nback here later.\n\nOK, still with me? To give us an example to look at, let’s go back to the earlier repository\nwith \"hello\" and \"example\" file, and bring ourselves back to the pre-merge state:\n\n$ git show-branch --more=2 master mybranch\n! [master] Merge work in mybranch\n* [mybranch] Merge work in mybranch\n--\n-- [master] Merge work in mybranch\n+* [master^2] Some work.\n+* [master^] Some fun.\n\n\nRemember, before running git merge, our master head was at \"Some fun.\" commit, while our\nmybranch head was at \"Some work.\" commit.\n\n$ git switch -C mybranch master^2\n$ git switch master\n$ git reset --hard master^\n\n\nAfter rewinding, the commit structure should look like this:\n\n$ git show-branch\n* [master] Some fun.\n! [mybranch] Some work.\n--\n*  [master] Some fun.\n+ [mybranch] Some work.\n*+ [master^] Initial commit\n\n\nNow we are ready to experiment with the merge by hand.\n\ngit merge command, when merging two branches, uses 3-way merge algorithm. First, it finds the\ncommon ancestor between them. The command it uses is git merge-base:\n\n$ mb=$(git merge-base HEAD mybranch)\n\n\nThe command writes the commit object name of the common ancestor to the standard output, so\nwe captured its output to a variable, because we will be using it in the next step. By the\nway, the common ancestor commit is the \"Initial commit\" commit in this case. You can tell it\nby:\n\n$ git name-rev --name-only --tags $mb\nmy-first-tag\n\n\nAfter finding out a common ancestor commit, the second step is this:\n\n$ git read-tree -m -u $mb HEAD mybranch\n\n\nThis is the same git read-tree command we have already seen, but it takes three trees, unlike\nprevious examples. This reads the contents of each tree into different stage in the index\nfile (the first tree goes to stage 1, the second to stage 2, etc.). After reading three trees\ninto three stages, the paths that are the same in all three stages are collapsed into stage\n0. Also paths that are the same in two of three stages are collapsed into stage 0, taking the\nSHA-1 from either stage 2 or stage 3, whichever is different from stage 1 (i.e. only one side\nchanged from the common ancestor).\n\nAfter collapsing operation, paths that are different in three trees are left in non-zero\nstages. At this point, you can inspect the index file with this command:\n\n$ git ls-files --stage\n100644 7f8b141b65fdcee47321e399a2598a235a032422 0       example\n100644 557db03de997c86a4a028e1ebd3a1ceb225be238 1       hello\n100644 ba42a2a96e3027f3333e13ede4ccf4498c3ae942 2       hello\n100644 cc44c73eb783565da5831b4d820c962954019b69 3       hello\n\n\nIn our example of only two files, we did not have unchanged files so only example resulted in\ncollapsing. But in real-life large projects, when only a small number of files change in one\ncommit, this collapsing tends to trivially merge most of the paths fairly quickly, leaving\nonly a handful of real changes in non-zero stages.\n\nTo look at only non-zero stages, use --unmerged flag:\n\n$ git ls-files --unmerged\n100644 557db03de997c86a4a028e1ebd3a1ceb225be238 1       hello\n100644 ba42a2a96e3027f3333e13ede4ccf4498c3ae942 2       hello\n100644 cc44c73eb783565da5831b4d820c962954019b69 3       hello\n\n\nThe next step of merging is to merge these three versions of the file, using 3-way merge.\nThis is done by giving git merge-one-file command as one of the arguments to git merge-index\ncommand:\n\n$ git merge-index git-merge-one-file hello\nAuto-merging hello\nERROR: Merge conflict in hello\nfatal: merge program failed\n\n\ngit merge-one-file script is called with parameters to describe those three versions, and is\nresponsible to leave the merge results in the working tree. It is a fairly straightforward\nshell script, and eventually calls merge program from RCS suite to perform a file-level 3-way\nmerge. In this case, merge detects conflicts, and the merge result with conflict marks is\nleft in the working tree.. This can be seen if you run ls-files --stage again at this point:\n\n$ git ls-files --stage\n100644 7f8b141b65fdcee47321e399a2598a235a032422 0       example\n100644 557db03de997c86a4a028e1ebd3a1ceb225be238 1       hello\n100644 ba42a2a96e3027f3333e13ede4ccf4498c3ae942 2       hello\n100644 cc44c73eb783565da5831b4d820c962954019b69 3       hello\n\n\nThis is the state of the index file and the working file after git merge returns control back\nto you, leaving the conflicting merge for you to resolve. Notice that the path hello is still\nunmerged, and what you see with git diff at this point is differences since stage 2 (i.e.\nyour version).\n",
            "subsections": []
        },
        "PUBLISHING YOUR WORK": {
            "content": "So, we can use somebody else’s work from a remote repository, but how can you prepare a\nrepository to let other people pull from it?\n\nYou do your real work in your working tree that has your primary repository hanging under it\nas its .git subdirectory. You could make that repository accessible remotely and ask people\nto pull from it, but in practice that is not the way things are usually done. A recommended\nway is to have a public repository, make it reachable by other people, and when the changes\nyou made in your primary working tree are in good shape, update the public repository from\nit. This is often called pushing.\n\nNote\n\nThis public repository could further be mirrored, and that is how Git repositories at\nkernel.org are managed.\n\nPublishing the changes from your local (private) repository to your remote (public)\nrepository requires a write privilege on the remote machine. You need to have an SSH account\nthere to run a single command, git-receive-pack.\n\nFirst, you need to create an empty repository on the remote machine that will house your\npublic repository. This empty repository will be populated and be kept up to date by pushing\ninto it later. Obviously, this repository creation needs to be done only once.\n\nNote\n\ngit push uses a pair of commands, git send-pack on your local machine, and\ngit-receive-pack on the remote machine. The communication between the two over the\nnetwork internally uses an SSH connection.\n\nYour private repository’s Git directory is usually .git, but your public repository is often\nnamed after the project name, i.e. <project>.git. Let’s create such a public repository for\nproject my-git. After logging into the remote machine, create an empty directory:\n\n$ mkdir my-git.git\n\n\nThen, make that directory into a Git repository by running git init, but this time, since its\nname is not the usual .git, we do things slightly differently:\n\n$ GITDIR=my-git.git git init\n\n\nMake sure this directory is available for others you want your changes to be pulled via the\ntransport of your choice. Also you need to make sure that you have the git-receive-pack\nprogram on the $PATH.\n\nNote\n\nMany installations of sshd do not invoke your shell as the login shell when you directly\nrun programs; what this means is that if your login shell is bash, only .bashrc is read\nand not .bashprofile. As a workaround, make sure .bashrc sets up $PATH so that you can\nrun git-receive-pack program.\n\nNote\n\nIf you plan to publish this repository to be accessed over http, you should do mv\nmy-git.git/hooks/post-update.sample my-git.git/hooks/post-update at this point. This\nmakes sure that every time you push into this repository, git update-server-info is run.\n\nYour \"public repository\" is now ready to accept your changes. Come back to the machine you\nhave your private repository. From there, run this command:\n\n$ git push <public-host>:/path/to/my-git.git master\n\n\nThis synchronizes your public repository to match the named branch head (i.e. master in this\ncase) and objects reachable from them in your current repository.\n\nAs a real example, this is how I update my public Git repository. Kernel.org mirror network\ntakes care of the propagation to other publicly visible machines:\n\n$ git push master.kernel.org:/pub/scm/git/git.git/\n\n",
            "subsections": []
        },
        "PACKING YOUR REPOSITORY": {
            "content": "Earlier, we saw that one file under .git/objects/??/ directory is stored for each Git object\nyou create. This representation is efficient to create atomically and safely, but not so\nconvenient to transport over the network. Since Git objects are immutable once they are\ncreated, there is a way to optimize the storage by \"packing them together\". The command\n\n$ git repack\n\n\nwill do it for you. If you followed the tutorial examples, you would have accumulated about\n17 objects in .git/objects/??/ directories by now. git repack tells you how many objects it\npacked, and stores the packed file in the .git/objects/pack directory.\n\nNote\n\nYou will see two files, pack-*.pack and pack-*.idx, in .git/objects/pack directory. They\nare closely related to each other, and if you ever copy them by hand to a different\nrepository for whatever reason, you should make sure you copy them together. The former\nholds all the data from the objects in the pack, and the latter holds the index for\nrandom access.\n\nIf you are paranoid, running git verify-pack command would detect if you have a corrupt pack,\nbut do not worry too much. Our programs are always perfect ;-).\n\nOnce you have packed objects, you do not need to leave the unpacked objects that are\ncontained in the pack file anymore.\n\n$ git prune-packed\n\n\nwould remove them for you.\n\nYou can try running find .git/objects -type f before and after you run git prune-packed if\nyou are curious. Also git count-objects would tell you how many unpacked objects are in your\nrepository and how much space they are consuming.\n\nNote\n\ngit pull is slightly cumbersome for HTTP transport, as a packed repository may contain\nrelatively few objects in a relatively large pack. If you expect many HTTP pulls from\nyour public repository you might want to repack & prune often, or never.\n\nIf you run git repack again at this point, it will say \"Nothing new to pack.\". Once you\ncontinue your development and accumulate the changes, running git repack again will create a\nnew pack, that contains objects created since you packed your repository the last time. We\nrecommend that you pack your project soon after the initial import (unless you are starting\nyour project from scratch), and then run git repack every once in a while, depending on how\nactive your project is.\n\nWhen a repository is synchronized via git push and git pull objects packed in the source\nrepository are usually stored unpacked in the destination. While this allows you to use\ndifferent packing strategies on both ends, it also means you may need to repack both\nrepositories every once in a while.\n",
            "subsections": []
        },
        "WORKING WITH OTHERS": {
            "content": "Although Git is a truly distributed system, it is often convenient to organize your project\nwith an informal hierarchy of developers. Linux kernel development is run this way. There is\na nice illustration (page 17, \"Merges to Mainline\") in \u001b[34mRandy Dunlap’s presentation[2].\n\nIt should be stressed that this hierarchy is purely informal. There is nothing fundamental in\nGit that enforces the \"chain of patch flow\" this hierarchy implies. You do not have to pull\nfrom only one remote repository.\n\nA recommended workflow for a \"project lead\" goes like this:\n\n1. Prepare your primary repository on your local machine. Your work is done there.\n\n2. Prepare a public repository accessible to others.\n\nIf other people are pulling from your repository over dumb transport protocols (HTTP),\nyou need to keep this repository dumb transport friendly. After git init,\n$GITDIR/hooks/post-update.sample copied from the standard templates would contain a call\nto git update-server-info but you need to manually enable the hook with mv\npost-update.sample post-update. This makes sure git update-server-info keeps the\nnecessary files up to date.\n\n3. Push into the public repository from your primary repository.\n\n4. git repack the public repository. This establishes a big pack that contains the initial\nset of objects as the baseline, and possibly git prune if the transport used for pulling\nfrom your repository supports packed repositories.\n\n5. Keep working in your primary repository. Your changes include modifications of your own,\npatches you receive via e-mails, and merges resulting from pulling the \"public\"\nrepositories of your \"subsystem maintainers\".\n\nYou can repack this private repository whenever you feel like.\n\n6. Push your changes to the public repository, and announce it to the public.\n\n7. Every once in a while, git repack the public repository. Go back to step 5. and continue\nworking.\n\nA recommended work cycle for a \"subsystem maintainer\" who works on that project and has an\nown \"public repository\" goes like this:\n\n1. Prepare your work repository, by running git clone on the public repository of the\n\"project lead\". The URL used for the initial cloning is stored in the remote.origin.url\nconfiguration variable.\n\n2. Prepare a public repository accessible to others, just like the \"project lead\" person\ndoes.\n\n3. Copy over the packed files from \"project lead\" public repository to your public\nrepository, unless the \"project lead\" repository lives on the same machine as yours. In\nthe latter case, you can use objects/info/alternates file to point at the repository you\nare borrowing from.\n\n4. Push into the public repository from your primary repository. Run git repack, and\npossibly git prune if the transport used for pulling from your repository supports packed\nrepositories.\n\n5. Keep working in your primary repository. Your changes include modifications of your own,\npatches you receive via e-mails, and merges resulting from pulling the \"public\"\nrepositories of your \"project lead\" and possibly your \"sub-subsystem maintainers\".\n\nYou can repack this private repository whenever you feel like.\n\n6. Push your changes to your public repository, and ask your \"project lead\" and possibly\nyour \"sub-subsystem maintainers\" to pull from it.\n\n7. Every once in a while, git repack the public repository. Go back to step 5. and continue\nworking.\n\nA recommended work cycle for an \"individual developer\" who does not have a \"public\"\nrepository is somewhat different. It goes like this:\n\n1. Prepare your work repository, by git clone the public repository of the \"project lead\"\n(or a \"subsystem maintainer\", if you work on a subsystem). The URL used for the initial\ncloning is stored in the remote.origin.url configuration variable.\n\n2. Do your work in your repository on master branch.\n\n3. Run git fetch origin from the public repository of your upstream every once in a while.\nThis does only the first half of git pull but does not merge. The head of the public\nrepository is stored in .git/refs/remotes/origin/master.\n\n4. Use git cherry origin to see which ones of your patches were accepted, and/or use git\nrebase origin to port your unmerged changes forward to the updated upstream.\n\n5. Use git format-patch origin to prepare patches for e-mail submission to your upstream and\nsend it out. Go back to step 2. and continue.\n\nWORKING WITH OTHERS, SHARED REPOSITORY STYLE\nIf you are coming from a CVS background, the style of cooperation suggested in the previous\nsection may be new to you. You do not have to worry. Git supports the \"shared public\nrepository\" style of cooperation you are probably more familiar with as well.\n\nSee gitcvs-migration(7) for the details.\n",
            "subsections": []
        },
        "BUNDLING YOUR WORK TOGETHER": {
            "content": "It is likely that you will be working on more than one thing at a time. It is easy to manage\nthose more-or-less independent tasks using branches with Git.\n\nWe have already seen how branches work previously, with \"fun and work\" example using two\nbranches. The idea is the same if there are more than two branches. Let’s say you started out\nfrom \"master\" head, and have some new code in the \"master\" branch, and two independent fixes\nin the \"commit-fix\" and \"diff-fix\" branches:\n\n$ git show-branch\n! [commit-fix] Fix commit message normalization.\n! [diff-fix] Fix rename detection.\n* [master] Release candidate #1\n---\n+  [diff-fix] Fix rename detection.\n+  [diff-fix~1] Better common substring algorithm.\n+   [commit-fix] Fix commit message normalization.\n* [master] Release candidate #1\n++* [diff-fix~2] Pretty-print messages.\n\n\nBoth fixes are tested well, and at this point, you want to merge in both of them. You could\nmerge in diff-fix first and then commit-fix next, like this:\n\n$ git merge -m \"Merge fix in diff-fix\" diff-fix\n$ git merge -m \"Merge fix in commit-fix\" commit-fix\n\n\nWhich would result in:\n\n$ git show-branch\n! [commit-fix] Fix commit message normalization.\n! [diff-fix] Fix rename detection.\n* [master] Merge fix in commit-fix\n---\n- [master] Merge fix in commit-fix\n+ * [commit-fix] Fix commit message normalization.\n- [master~1] Merge fix in diff-fix\n+* [diff-fix] Fix rename detection.\n+* [diff-fix~1] Better common substring algorithm.\n* [master~2] Release candidate #1\n++* [master~3] Pretty-print messages.\n\n\nHowever, there is no particular reason to merge in one branch first and the other next, when\nwhat you have are a set of truly independent changes (if the order mattered, then they are\nnot independent by definition). You could instead merge those two branches into the current\nbranch at once. First let’s undo what we just did and start over. We would want to get the\nmaster branch before these two merges by resetting it to master~2:\n\n$ git reset --hard master~2\n\n\nYou can make sure git show-branch matches the state before those two git merge you just did.\nThen, instead of running two git merge commands in a row, you would merge these two branch\nheads (this is known as making an Octopus):\n\n$ git merge commit-fix diff-fix\n$ git show-branch\n! [commit-fix] Fix commit message normalization.\n! [diff-fix] Fix rename detection.\n* [master] Octopus merge of branches 'diff-fix' and 'commit-fix'\n---\n- [master] Octopus merge of branches 'diff-fix' and 'commit-fix'\n+ * [commit-fix] Fix commit message normalization.\n+* [diff-fix] Fix rename detection.\n+* [diff-fix~1] Better common substring algorithm.\n* [master~1] Release candidate #1\n++* [master~2] Pretty-print messages.\n\n\nNote that you should not do Octopus just because you can. An octopus is a valid thing to do\nand often makes it easier to view the commit history if you are merging more than two\nindependent changes at the same time. However, if you have merge conflicts with any of the\nbranches you are merging in and need to hand resolve, that is an indication that the\ndevelopment happened in those branches were not independent after all, and you should merge\ntwo at a time, documenting how you resolved the conflicts, and the reason why you preferred\nchanges made in one side over the other. Otherwise it would make the project history harder\nto follow, not easier.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "gittutorial(7), gittutorial-2(7), gitcvs-migration(7), git-help(1), giteveryday(7), \u001b[34mThe Git\n\u001b[34mUser’s Manual[1]\n",
            "subsections": []
        },
        "GIT": {
            "content": "Part of the git(1) suite\n",
            "subsections": []
        },
        "NOTES": {
            "content": "1. the Git User Manual\nfile:///usr/share/doc/git/html/user-manual.html\n\n2. Randy Dunlap’s presentation\nhttps://web.archive.org/web/20120915203609/http://www.xenotime.net/linux/mentor/linux-mentoring-2006.pdf\n\nGit 2.43.0                                   07/02/2025                          GITCORE-TUTORIAL(7)",
            "subsections": []
        }
    },
    "summary": "gitcore-tutorial - A Git core tutorial for developers",
    "flags": [],
    "examples": [],
    "see_also": [
        {
            "name": "gittutorial",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/gittutorial/7/json"
        },
        {
            "name": "gittutorial-2",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/gittutorial-2/7/json"
        },
        {
            "name": "gitcvs-migration",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/gitcvs-migration/7/json"
        },
        {
            "name": "git-help",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/git-help/1/json"
        },
        {
            "name": "giteveryday",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/giteveryday/7/json"
        }
    ]
}