{
    "mode": "info",
    "parameter": "gittutorial",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/info/gittutorial/json",
    "generated": "2026-07-12T04:40:16Z",
    "synopsis": "git *",
    "sections": {
        "NAME": {
            "content": "gittutorial - A tutorial introduction to Git\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "git *\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This tutorial explains how to import a new project into Git, make\nchanges to it, and share changes with other developers.\n\nIf you are instead primarily interested in using Git to fetch a\nproject, for example, to test the latest version, you may prefer to\nstart with the first two chapters of The Git User's Manual[1].\n\nFirst, note that you can get documentation for a command such as git\nlog --graph with:\n\n$ man git-log\n\nor:\n\n$ git help log\n\nWith the latter, you can use the manual viewer of your choice; see git-\nhelp(1) for more information.\n\nIt is a good idea to introduce yourself to Git with your name and\npublic email address before doing any operation. The easiest way to do\nso is:\n\n$ git config --global user.name \"Your Name Comes Here\"\n$ git config --global user.email you@yourdomain.example.com\n",
            "subsections": []
        },
        "IMPORTING A NEW PROJECT": {
            "content": "Assume you have a tarball project.tar.gz with your initial work. You\ncan place it under Git revision control as follows.\n\n$ tar xzf project.tar.gz\n$ cd project\n$ git init\n\nGit will reply\n\nInitialized empty Git repository in .git/\n\nYou've now initialized the working directory--you may notice a new\ndirectory created, named \".git\".\n\nNext, tell Git to take a snapshot of the contents of all files under\nthe current directory (note the .), with git add:\n\n$ git add .\n\nThis snapshot is now stored in a temporary staging area which Git calls\nthe \"index\". You can permanently store the contents of the index in the\nrepository with git commit:\n\n$ git commit\n\nThis will prompt you for a commit message. You've now stored the first\nversion of your project in Git.\n",
            "subsections": []
        },
        "MAKING CHANGES": {
            "content": "Modify some files, then add their updated contents to the index:\n\n$ git add file1 file2 file3\n\nYou are now ready to commit. You can see what is about to be committed\nusing git diff with the --cached option:\n\n$ git diff --cached\n\n(Without --cached, git diff will show you any changes that you've made\nbut not yet added to the index.) You can also get a brief summary of\nthe situation with git status:\n\n$ git status\nOn branch master\nChanges to be committed:\nYour branch is up to date with 'origin/master'.\n(use \"git restore --staged <file>...\" to unstage)\n\nmodified:   file1\nmodified:   file2\nmodified:   file3\n\nIf you need to make any further adjustments, do so now, and then add\nany newly modified content to the index. Finally, commit your changes\nwith:\n\n$ git commit\n\nThis will again prompt you for a message describing the change, and\nthen record a new version of the project.\n\nAlternatively, instead of running git add beforehand, you can use\n\n$ git commit -a\n\nwhich will automatically notice any modified (but not new) files, add\nthem to the index, and commit, all in one step.\n\nA note on commit messages: Though not required, it's a good idea to\nbegin the commit message with a single short (less than 50 character)\nline summarizing the change, followed by a blank line and then a more\nthorough description. The text up to the first blank line in a commit\nmessage is treated as the commit title, and that title is used\nthroughout Git. For example, git-format-patch(1) turns a commit into\nemail, and it uses the title on the Subject line and the rest of the\ncommit in the body.\n",
            "subsections": []
        },
        "GIT TRACKS CONTENT NOT FILES": {
            "content": "Many revision control systems provide an add command that tells the\nsystem to start tracking changes to a new file. Git's add command does\nsomething simpler and more powerful: git add is used both for new and\nnewly modified files, and in both cases it takes a snapshot of the\ngiven files and stages that content in the index, ready for inclusion\nin the next commit.\n",
            "subsections": []
        },
        "VIEWING PROJECT HISTORY": {
            "content": "At any point you can view the history of your changes using\n\n$ git log\n\nIf you also want to see complete diffs at each step, use\n\n$ git log -p\n\nOften the overview of the change is useful to get a feel of each step\n\n$ git log --stat --summary\n",
            "subsections": []
        },
        "MANAGING BRANCHES": {
            "content": "A single Git repository can maintain multiple branches of development.\nTo create a new branch named \"experimental\", use\n\n$ git branch experimental\n\nIf you now run\n\n$ git branch\n\nyou'll get a list of all existing branches:\n\nexperimental\n* master\n\nThe \"experimental\" branch is the one you just created, and the \"master\"\nbranch is a default branch that was created for you automatically. The\nasterisk marks the branch you are currently on; type\n\n$ git switch experimental\n\nto switch to the experimental branch. Now edit a file, commit the\nchange, and switch back to the master branch:\n\n(edit file)\n$ git commit -a\n$ git switch master\n\nCheck that the change you made is no longer visible, since it was made\non the experimental branch and you're back on the master branch.\n\nYou can make a different change on the master branch:\n\n(edit file)\n$ git commit -a\n\nat this point the two branches have diverged, with different changes\nmade in each. To merge the changes made in experimental into master,\nrun\n\n$ git merge experimental\n\nIf the changes don't conflict, you're done. If there are conflicts,\nmarkers will be left in the problematic files showing the conflict;\n\n$ git diff\n\nwill show this. Once you've edited the files to resolve the conflicts,\n\n$ git commit -a\n\nwill commit the result of the merge. Finally,\n\n$ gitk\n\nwill show a nice graphical representation of the resulting history.\n\nAt this point you could delete the experimental branch with\n\n$ git branch -d experimental\n\nThis command ensures that the changes in the experimental branch are\nalready in the current branch.\n\nIf you develop on a branch crazy-idea, then regret it, you can always\ndelete the branch with\n\n$ git branch -D crazy-idea\n\nBranches are cheap and easy, so this is a good way to try something\nout.\n",
            "subsections": []
        },
        "USING GIT FOR COLLABORATION": {
            "content": "Suppose that Alice has started a new project with a Git repository in\n/home/alice/project, and that Bob, who has a home directory on the same\nmachine, wants to contribute.\n\nBob begins with:\n\nbob$ git clone /home/alice/project myrepo\n\nThis creates a new directory \"myrepo\" containing a clone of Alice's\nrepository. The clone is on an equal footing with the original project,\npossessing its own copy of the original project's history.\n\nBob then makes some changes and commits them:\n\n(edit files)\nbob$ git commit -a\n(repeat as necessary)\n\nWhen he's ready, he tells Alice to pull changes from the repository at\n/home/bob/myrepo. She does this with:\n\nalice$ cd /home/alice/project\nalice$ git pull /home/bob/myrepo master\n\nThis merges the changes from Bob's \"master\" branch into Alice's current\nbranch. If Alice has made her own changes in the meantime, then she may\nneed to manually fix any conflicts.\n\nThe \"pull\" command thus performs two operations: it fetches changes\nfrom a remote branch, then merges them into the current branch.\n\nNote that in general, Alice would want her local changes committed\nbefore initiating this \"pull\". If Bob's work conflicts with what Alice\ndid since their histories forked, Alice will use her working tree and\nthe index to resolve conflicts, and existing local changes will\ninterfere with the conflict resolution process (Git will still perform\nthe fetch but will refuse to merge -- Alice will have to get rid of her\nlocal changes in some way and pull again when this happens).\n\nAlice can peek at what Bob did without merging first, using the \"fetch\"\ncommand; this allows Alice to inspect what Bob did, using a special\nsymbol \"FETCHHEAD\", in order to determine if he has anything worth\npulling, like this:\n\nalice$ git fetch /home/bob/myrepo master\nalice$ git log -p HEAD..FETCHHEAD\n\nThis operation is safe even if Alice has uncommitted local changes. The\nrange notation \"HEAD..FETCHHEAD\" means \"show everything that is\nreachable from the FETCHHEAD but exclude anything that is reachable\nfrom HEAD\". Alice already knows everything that leads to her current\nstate (HEAD), and reviews what Bob has in his state (FETCHHEAD) that\nshe has not seen with this command.\n\nIf Alice wants to visualize what Bob did since their histories forked\nshe can issue the following command:\n\n$ gitk HEAD..FETCHHEAD\n\nThis uses the same two-dot range notation we saw earlier with git log.\n\nAlice may want to view what both of them did since they forked. She can\nuse three-dot form instead of the two-dot form:\n\n$ gitk HEAD...FETCHHEAD\n\nThis means \"show everything that is reachable from either one, but\nexclude anything that is reachable from both of them\".\n\nPlease note that these range notation can be used with both gitk and\n\"git log\".\n\nAfter inspecting what Bob did, if there is nothing urgent, Alice may\ndecide to continue working without pulling from Bob. If Bob's history\ndoes have something Alice would immediately need, Alice may choose to\nstash her work-in-progress first, do a \"pull\", and then finally unstash\nher work-in-progress on top of the resulting history.\n\nWhen you are working in a small closely knit group, it is not unusual\nto interact with the same repository over and over again. By defining\nremote repository shorthand, you can make it easier:\n\nalice$ git remote add bob /home/bob/myrepo\n\nWith this, Alice can perform the first part of the \"pull\" operation\nalone using the git fetch command without merging them with her own\nbranch, using:\n\nalice$ git fetch bob\n\nUnlike the longhand form, when Alice fetches from Bob using a remote\nrepository shorthand set up with git remote, what was fetched is stored\nin a remote-tracking branch, in this case bob/master. So after this:\n\nalice$ git log -p master..bob/master\n\nshows a list of all the changes that Bob made since he branched from\nAlice's master branch.\n\nAfter examining those changes, Alice could merge the changes into her\nmaster branch:\n\nalice$ git merge bob/master\n\nThis merge can also be done by pulling from her own remote-tracking\nbranch, like this:\n\nalice$ git pull . remotes/bob/master\n\nNote that git pull always merges into the current branch, regardless of\nwhat else is given on the command line.\n\nLater, Bob can update his repo with Alice's latest changes using\n\nbob$ git pull\n\nNote that he doesn't need to give the path to Alice's repository; when\nBob cloned Alice's repository, Git stored the location of her\nrepository in the repository configuration, and that location is used\nfor pulls:\n\nbob$ git config --get remote.origin.url\n/home/alice/project\n\n(The complete configuration created by git clone is visible using git\nconfig -l, and the git-config(1) man page explains the meaning of each\noption.)\n\nGit also keeps a pristine copy of Alice's master branch under the name\n\"origin/master\":\n\nbob$ git branch -r\norigin/master\n\nIf Bob later decides to work from a different host, he can still\nperform clones and pulls using the ssh protocol:\n\nbob$ git clone alice.org:/home/alice/project myrepo\n\nAlternatively, Git has a native protocol, or can use http; see git-\npull(1) for details.\n\nGit can also be used in a CVS-like mode, with a central repository that\nvarious users push changes to; see git-push(1) and gitcvs-migration(7).\n",
            "subsections": []
        },
        "EXPLORING HISTORY": {
            "content": "Git history is represented as a series of interrelated commits. We have\nalready seen that the git log command can list those commits. Note that\nfirst line of each git log entry also gives a name for the commit:\n\n$ git log\ncommit c82a22c39cbc32576f64f5c6b3f24b99ea8149c7\nAuthor: Junio C Hamano <junkio@cox.net>\nDate:   Tue May 16 17:18:22 2006 -0700\n\nmerge-base: Clarify the comments on post processing.\n\nWe can give this name to git show to see the details about this commit.\n\n$ git show c82a22c39cbc32576f64f5c6b3f24b99ea8149c7\n\nBut there are other ways to refer to commits. You can use any initial\npart of the name that is long enough to uniquely identify the commit:\n\n$ git show c82a22c39c   # the first few characters of the name are\n# usually enough\n$ git show HEAD         # the tip of the current branch\n$ git show experimental # the tip of the \"experimental\" branch\n\nEvery commit usually has one \"parent\" commit which points to the\nprevious state of the project:\n\n$ git show HEAD^  # to see the parent of HEAD\n$ git show HEAD^^ # to see the grandparent of HEAD\n$ git show HEAD~4 # to see the great-great grandparent of HEAD\n\nNote that merge commits may have more than one parent:\n\n$ git show HEAD^1 # show the first parent of HEAD (same as HEAD^)\n$ git show HEAD^2 # show the second parent of HEAD\n\nYou can also give commits names of your own; after running\n\n$ git tag v2.5 1b2e1d63ff\n\nyou can refer to 1b2e1d63ff by the name \"v2.5\". If you intend to share\nthis name with other people (for example, to identify a release\nversion), you should create a \"tag\" object, and perhaps sign it; see\ngit-tag(1) for details.\n\nAny Git command that needs to know a commit can take any of these\nnames. For example:\n\n$ git diff v2.5 HEAD     # compare the current HEAD to v2.5\n$ git branch stable v2.5 # start a new branch named \"stable\" based\n# at v2.5\n$ git reset --hard HEAD^ # reset your current branch and working\n# directory to its state at HEAD^\n\nBe careful with that last command: in addition to losing any changes in\nthe working directory, it will also remove all later commits from this\nbranch. If this branch is the only branch containing those commits,\nthey will be lost. Also, don't use git reset on a publicly-visible\nbranch that other developers pull from, as it will force needless\nmerges on other developers to clean up the history. If you need to undo\nchanges that you have pushed, use git revert instead.\n\nThe git grep command can search for strings in any version of your\nproject, so\n\n$ git grep \"hello\" v2.5\n\nsearches for all occurrences of \"hello\" in v2.5.\n\nIf you leave out the commit name, git grep will search any of the files\nit manages in your current directory. So\n\n$ git grep \"hello\"\n\nis a quick way to search just the files that are tracked by Git.\n\nMany Git commands also take sets of commits, which can be specified in\na number of ways. Here are some examples with git log:\n\n$ git log v2.5..v2.6            # commits between v2.5 and v2.6\n$ git log v2.5..                # commits since v2.5\n$ git log --since=\"2 weeks ago\" # commits from the last 2 weeks\n$ git log v2.5.. Makefile       # commits since v2.5 which modify\n# Makefile\n\nYou can also give git log a \"range\" of commits where the first is not\nnecessarily an ancestor of the second; for example, if the tips of the\nbranches \"stable\" and \"master\" diverged from a common commit some time\nago, then\n\n$ git log stable..master\n\nwill list commits made in the master branch but not in the stable\nbranch, while\n\n$ git log master..stable\n\nwill show the list of commits made on the stable branch but not the\nmaster branch.\n\nThe git log command has a weakness: it must present commits in a list.\nWhen the history has lines of development that diverged and then merged\nback together, the order in which git log presents those commits is\nmeaningless.\n\nMost projects with multiple contributors (such as the Linux kernel, or\nGit itself) have frequent merges, and gitk does a better job of\nvisualizing their history. For example,\n\n$ gitk --since=\"2 weeks ago\" drivers/\n\nallows you to browse any commits from the last 2 weeks of commits that\nmodified files under the \"drivers\" directory. (Note: you can adjust\ngitk's fonts by holding down the control key while pressing \"-\" or\n\"+\".)\n\nFinally, most commands that take filenames will optionally allow you to\nprecede any filename by a commit, to specify a particular version of\nthe file:\n\n$ git diff v2.5:Makefile HEAD:Makefile.in\n\nYou can also use git show to see any such file:\n\n$ git show v2.5:Makefile\n",
            "subsections": []
        },
        "NEXT STEPS": {
            "content": "This tutorial should be enough to perform basic distributed revision\ncontrol for your projects. However, to fully understand the depth and\npower of Git you need to understand two simple ideas on which it is\nbased:\n\no   The object database is the rather elegant system used to store the\nhistory of your project--files, directories, and commits.\n\no   The index file is a cache of the state of a directory tree, used to\ncreate commits, check out working directories, and hold the various\ntrees involved in a merge.\n\nPart two of this tutorial explains the object database, the index file,\nand a few other odds and ends that you'll need to make the most of Git.\nYou can find it at gittutorial-2(7).\n\nIf you don't want to continue with that right away, a few other\ndigressions that may be interesting at this point are:\n\no   git-format-patch(1), git-am(1): These convert series of git commits\ninto emailed patches, and vice versa, useful for projects such as\nthe Linux kernel which rely heavily on emailed patches.\n\no   git-bisect(1): When there is a regression in your project, one way\nto track down the bug is by searching through the history to find\nthe exact commit that's to blame. Git bisect can help you perform a\nbinary search for that commit. It is smart enough to perform a\nclose-to-optimal search even in the case of complex non-linear\nhistory with lots of merged branches.\n\no   gitworkflows(7): Gives an overview of recommended workflows.\n\no   giteveryday(7): Everyday Git with 20 Commands Or So.\n\no   gitcvs-migration(7): Git for CVS users.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "gittutorial-2(7), gitcvs-migration(7), gitcore-tutorial(7),\ngitglossary(7), git-help(1), gitworkflows(7), giteveryday(7), The Git\nUser's Manual[1]\n",
            "subsections": []
        },
        "GIT": {
            "content": "Part of the git(1) suite\n",
            "subsections": []
        },
        "NOTES": {
            "content": "1. The Git User's Manual\nfile:///usr/share/doc/git/html/user-manual.html\n\nGit 2.34.1                        02/26/2026                    GITTUTORIAL(7)",
            "subsections": []
        }
    },
    "summary": "gittutorial - A tutorial introduction to Git",
    "flags": [],
    "examples": [],
    "see_also": [
        {
            "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": "gitcore-tutorial",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/gitcore-tutorial/7/json"
        },
        {
            "name": "gitglossary",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/gitglossary/7/json"
        },
        {
            "name": "git-help",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/git-help/1/json"
        },
        {
            "name": "gitworkflows",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/gitworkflows/7/json"
        },
        {
            "name": "giteveryday",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/giteveryday/7/json"
        }
    ]
}