{"id":7649,"date":"2018-06-25T00:10:25","date_gmt":"2018-06-24T16:10:25","guid":{"rendered":"http:\/\/rmohan.com\/?p=7649"},"modified":"2018-06-25T00:10:25","modified_gmt":"2018-06-24T16:10:25","slug":"git-fundamentals","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=7649","title":{"rendered":"Git Fundamentals"},"content":{"rendered":"<h1 id=\"8352\" class=\"graf graf--h3 graf--leading graf--title\">Git Fundamentals<\/h1>\n<p>&nbsp;<\/p>\n<section class=\"section section--body section--first\">\n<div class=\"section-content\">\n<div class=\"section-inner sectionLayout--insetColumn\">\n<p id=\"563d\" class=\"graf graf--p graf-after--h4\">Topics To be Covered<\/p>\n<ol class=\"postList\">\n<li id=\"99f8\" class=\"graf graf--li graf-after--p\">Installation<\/li>\n<\/ol>\n<p id=\"56cd\" class=\"graf graf--p graf-after--li\">2. Setup<\/p>\n<p id=\"d4bd\" class=\"graf graf--p graf-after--p\">3. Creating a Project<\/p>\n<p id=\"0efb\" class=\"graf graf--p graf-after--p\">4. Checking the status of the repository<\/p>\n<p id=\"0e21\" class=\"graf graf--p graf-after--p\">5. Making changes<\/p>\n<p id=\"f546\" class=\"graf graf--p graf-after--p\">6. Staging the changes<\/p>\n<p id=\"e021\" class=\"graf graf--p graf-after--p\">7. Staging and committing<\/p>\n<p id=\"3455\" class=\"graf graf--p graf-after--p\">8. Commiting the changes<\/p>\n<p id=\"a434\" class=\"graf graf--p graf-after--p\">9. Changes, not files<\/p>\n<p id=\"e0e4\" class=\"graf graf--p graf-after--p\">10. History<\/p>\n<p id=\"d660\" class=\"graf graf--p graf-after--p\">11. Aliases<\/p>\n<p id=\"750f\" class=\"graf graf--p graf-after--p\">12. Getting older versions<\/p>\n<p id=\"b4ce\" class=\"graf graf--p graf-after--p\">13. Tagging versions<\/p>\n<p id=\"75d0\" class=\"graf graf--p graf-after--p\">14. Discarding local changes (before staging)<\/p>\n<p id=\"746b\" class=\"graf graf--p graf-after--p\">15. Cancel Staged changes (before committing)<\/p>\n<p id=\"87c4\" class=\"graf graf--p graf-after--p graf--trailing\">16. Cancelling commits<\/p>\n<\/div>\n<\/div>\n<\/section>\n<section class=\"section section--body section--last\">\n<div class=\"section-divider\">\n<hr class=\"section-divider\" \/>\n<\/div>\n<div class=\"section-content\">\n<div class=\"section-inner sectionLayout--insetColumn\">\n<div class=\"aspectRatioPlaceholder is-locked\">\n<h3 id=\"be82\" class=\"graf graf--h3 graf-after--figure graf--leading\">1. Installing Git<\/h3>\n<h4 id=\"d619\" class=\"graf graf--h4 graf-after--h3\">Installing on\u00a0Linux<\/h4>\n<p id=\"84c3\" class=\"graf graf--p graf-after--h4\">If you want to install the basic Git tools on Linux via a binary installer, you can generally do so through the basic package-management tool that comes with your distribution. If you\u2019re on Fedora for example, you can use yum:<\/p>\n<pre id=\"0c97\" class=\"graf graf--pre graf-after--p\">$ sudo yum install git-all<\/pre>\n<p id=\"f8d0\" class=\"graf graf--p graf-after--pre\">If you\u2019re on a Debian-based distribution like Ubuntu, try apt-get:<\/p>\n<\/div>\n<pre id=\"c2cc\" class=\"graf graf--pre graf-after--p\">$ sudo apt-get install git-all<\/pre>\n<p id=\"2931\" class=\"graf graf--p graf-after--pre\">For more options, there are instructions for installing on several different Unix flavors on the Git website, at\u00a0<a class=\"markup--anchor markup--p-anchor\" href=\"http:\/\/git-scm.com\/download\/linux\" target=\"_blank\" rel=\"noopener\" data-href=\"http:\/\/git-scm.com\/download\/linux\"><em class=\"markup--em markup--p-em\">http:\/\/git-scm.com\/download\/linux<\/em><\/a>.<\/p>\n<h4 id=\"53cc\" class=\"graf graf--h4 graf-after--p\">Installing on\u00a0Mac<\/h4>\n<p id=\"6b55\" class=\"graf graf--p graf-after--h4\">There are several ways to install Git on a Mac. The easiest is probably to install the Xcode Command Line Tools. On Mavericks (10.9) or above you can do this simply by trying to run\u00a0<em class=\"markup--em markup--p-em\">git<\/em>\u00a0from the Terminal the very first time. If you don\u2019t have it installed already, it will prompt you to install it.<\/p>\n<p id=\"2444\" class=\"graf graf--p graf-after--p\">If you want a more up to date version, you can also install it via a binary installer. An OSX Git installer is maintained and available for download at the Git website, at\u00a0<a class=\"markup--anchor markup--p-anchor\" href=\"https:\/\/sourceforge.net\/projects\/git-osx-installer\/\" target=\"_blank\" rel=\"nofollow noopener\" data-href=\"https:\/\/sourceforge.net\/projects\/git-osx-installer\/\">https:\/\/sourceforge.net\/projects\/git-osx-installer\/<\/a><\/p>\n<\/div>\n<\/div>\n<p id=\"6508\" class=\"graf graf--p graf-after--figure\">You can also install it as part of the GitHub for Mac install. Their GUI Git tool has an option to install command line tools as well. You can download that tool from the GitHub for Mac website, at<a class=\"markup--anchor markup--p-anchor\" href=\"http:\/\/mac.github.com\/\" target=\"_blank\" rel=\"noopener\" data-href=\"http:\/\/mac.github.com\/\"><em class=\"markup--em markup--p-em\">http:\/\/mac.github.com<\/em><\/a>.<\/p>\n<h3 id=\"2838\" class=\"graf graf--h3 graf-after--p\">Installing on\u00a0Windows<\/h3>\n<p id=\"01c5\" class=\"graf graf--p graf-after--h3\">There are also a few ways to install Git on Windows. The most official build is available for download on the Git website. Just go to\u00a0<a class=\"markup--anchor markup--p-anchor\" href=\"https:\/\/git-for-windows.github.io\/\" target=\"_blank\" rel=\"nofollow noopener\" data-href=\"https:\/\/git-for-windows.github.io\/\">https:\/\/git-for-windows.github.io\/<\/a><\/p>\n<\/section>\n<p id=\"d090\" class=\"graf graf--p graf-after--figure\">Another easy way to get Git installed is by installing GitHub for Windows. The installer includes a command line version of Git as well as the GUI. It also works well with Powershell, and sets up solid credential caching and sane CRLF settings. We\u2019ll learn more about those things a little later, but suffice it to say they\u2019re things you want. You can download this from the GitHub for Windows website, at\u00a0<a class=\"markup--anchor markup--p-anchor\" href=\"http:\/\/windows.github.com\/\" target=\"_blank\" rel=\"noopener\" data-href=\"http:\/\/windows.github.com\/\"><em class=\"markup--em markup--p-em\">http:\/\/windows.github.com<\/em><\/a><\/p>\n<h3 id=\"8f7e\" class=\"graf graf--h3 graf-after--p\">2. One time Git Environment Setup<\/h3>\n<p id=\"3f32\" class=\"graf graf--p graf-after--h3\">Now that you have Git on your system, you\u2019ll want to do a few things to customize your Git environment. You should have to do these things only once; they\u2019ll stick around between upgrades. You can also change them at any time by running through the commands again.<\/p>\n<p id=\"a4c6\" class=\"graf graf--p graf-after--p\">Git comes with a tool called git config that lets you get and set configuration variables that control all aspects of how Git looks and operates. These variables can be stored in three different places:<\/p>\n<p id=\"dca9\" class=\"graf graf--p graf-after--p\">$ git config?\u2014?global user.name \u201cAravind G V\u201d<\/p>\n<p id=\"0e7e\" class=\"graf graf--p graf-after--p\">$ git config?\u2014?global user.email aravind_gv@intuit.com<\/p>\n<p id=\"4ba5\" class=\"graf graf--p graf-after--p\">$ git config?\u2014?global core.editor \u201cedit -w\u201d<\/p>\n<h3 id=\"5394\" class=\"graf graf--h3 graf-after--p\">3. Creating a\u00a0Project<\/h3>\n<h4 id=\"34f2\" class=\"graf graf--h4 graf-after--h3\">Create a new repository<\/h4>\n<p id=\"25cb\" class=\"graf graf--p graf-after--h4\">Create a New Folder or Do in Existing Folder if you want to add it to vcs<\/p>\n<pre id=\"7088\" class=\"graf graf--pre graf-after--p\">mkdir training\r\ncd training\r\ntouch hello.txt<\/pre>\n<h3 id=\"6211\" class=\"graf graf--h3 graf-after--pre\">Create a repository<\/h3>\n<p id=\"d468\" class=\"graf graf--p graf-after--h3\">So you have a directory that contains one file. Run the git init in order to create a git repo from that directory.<\/p>\n<h4 id=\"796b\" class=\"graf graf--h4 graf-after--p\">RUN:<\/h4>\n<pre id=\"f664\" class=\"graf graf--pre graf-after--h4\">git init<\/pre>\n<h4 id=\"eb35\" class=\"graf graf--h4 graf-after--pre\">RESULT:<\/h4>\n<pre id=\"5b35\" class=\"graf graf--pre graf-after--h4\">$ git init\r\nInitialized empty Git repository in \/Users\/agv\/git-training<\/pre>\n<p id=\"aec8\" class=\"graf graf--p graf-after--pre\">This creates a new subdirectory named\u00a0.git that contains all of your necessary repository files?\u2014?a Git repository skeleton. At this point, nothing in your project is tracked yet<\/p>\n<h3 id=\"6204\" class=\"graf graf--h3 graf-after--p\">Add the page to the repository<\/h3>\n<p id=\"6eda\" class=\"graf graf--p graf-after--h3\">Now let\u2019s add the \u201cHello, World\u201d page to the repository.<\/p>\n<h4 id=\"914f\" class=\"graf graf--h4 graf-after--p\">RUN:<\/h4>\n<pre id=\"acee\" class=\"graf graf--pre graf-after--h4\">git add hello.txt\r\ngit commit -m \"First Commit\"<\/pre>\n<p id=\"dcb2\" class=\"graf graf--p graf-after--pre\">You will see\u00a0\u2026<\/p>\n<h4 id=\"da73\" class=\"graf graf--h4 graf-after--p\">RESULT:<\/h4>\n<pre id=\"328f\" class=\"graf graf--pre graf-after--h4\">$ git add hello.txt\r\n$ git commit -m \"First Commit\"\r\n[master (root-commit) 2fc4372] First Commit\r\n 1 file changed, 0 insertions(+), 0 deletions(-)\r\n create mode 100644 hello.txt<\/pre>\n<h3 id=\"a188\" class=\"graf graf--h3 graf-after--pre\">Checking the status of the repository<\/h3>\n<p id=\"f563\" class=\"graf graf--p graf-after--h3\">Use the git status command, to check the current state of the repository.<\/p>\n<h4 id=\"cf0a\" class=\"graf graf--h4 graf-after--p\">RUN:<\/h4>\n<pre id=\"c570\" class=\"graf graf--pre graf-after--h4\">git status<\/pre>\n<h4 id=\"72eb\" class=\"graf graf--h4 graf-after--pre\">RESULT:<\/h4>\n<pre id=\"94f1\" class=\"graf graf--pre graf-after--h4\">$ git status\r\n# On branch master\r\nnothing to commit (working directory clean)<\/pre>\n<p id=\"76d8\" class=\"graf graf--p graf-after--pre\">The command checks the status and reports that there\u2019s nothing to commit, meaning the repository stores the current state of the working directory, and there are no changes to record.<\/p>\n<p id=\"6c78\" class=\"graf graf--p graf-after--p\">We will use the git status, to keep monitoring the states of both the working directory and the repository.<\/p>\n<h3 id=\"572e\" class=\"graf graf--h3 graf-after--p\"><a class=\"markup--anchor markup--h3-anchor\" href=\"https:\/\/githowto.com\/making_changes\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/githowto.com\/making_changes\">Making changes<\/a><\/h3>\n<h3 id=\"636b\" class=\"graf graf--h3 graf-after--h3\">Let\u2019s add some thing in text\u00a0file<\/h3>\n<pre id=\"9501\" class=\"graf graf--pre graf-after--h3\">vi hello.txt\r\nTest status<\/pre>\n<h3 id=\"2ea4\" class=\"graf graf--h3 graf-after--pre\">Checking the\u00a0status<\/h3>\n<p id=\"cb04\" class=\"graf graf--p graf-after--h3\">Check the working directory\u2019s status.<\/p>\n<h4 id=\"6761\" class=\"graf graf--h4 graf-after--p\">RUN:<\/h4>\n<pre id=\"acd4\" class=\"graf graf--pre graf-after--h4\">git status<\/pre>\n<p id=\"a3e0\" class=\"graf graf--p graf-after--pre\">You will see\u00a0\u2026<\/p>\n<h4 id=\"fcff\" class=\"graf graf--h4 graf-after--p\">RESULT:<\/h4>\n<pre id=\"2e3e\" class=\"graf graf--pre graf-after--h4\">$ git status\r\nOn branch master\r\nChanges not staged for commit:\r\n  (use \"git add &lt;file&gt;...\" to update what will be committed)\r\n  (use \"git checkout -- &lt;file&gt;...\" to discard changes in working directory)\r\nmodified:   hello.txt\r\nno changes added to commit (use \"git add\" and\/or \"git commit -a\")<\/pre>\n<p id=\"01e7\" class=\"graf graf--p graf-after--pre\">The first important aspect here is that git knows hello.txt file has been changed, but these changes are not yet committed to the repository.<\/p>\n<p id=\"5c02\" class=\"graf graf--p graf-after--p\">Another aspect is that the status message hints about what to do next. If you want to add these changes to the repository, use git add. To undo the changes use git checkout.<\/p>\n<h3 id=\"0345\" class=\"graf graf--h3 graf-after--p\">6. Staging the\u00a0changes<\/h3>\n<h4 id=\"aba1\" class=\"graf graf--h4 graf-after--h3\">Adding changes<\/h4>\n<p id=\"3662\" class=\"graf graf--p graf-after--h4\">Now command git to stage changes. Check the status<\/p>\n<h4 id=\"0eca\" class=\"graf graf--h4 graf-after--p\">RUN:<\/h4>\n<pre id=\"14f4\" class=\"graf graf--pre graf-after--h4\">git add hello.txt\r\ngit status<\/pre>\n<p id=\"3039\" class=\"graf graf--p graf-after--pre\">You will see\u00a0\u2026<\/p>\n<h4 id=\"2f67\" class=\"graf graf--h4 graf-after--p\">RESULT:<\/h4>\n<pre id=\"ae95\" class=\"graf graf--pre graf-after--h4\">$ git add hello.txt\r\n$ git status\r\n# On branch master\r\n# Changes to be committed:\r\n#   (use \"git reset HEAD &lt;file&gt;...\" to unstage)\r\n#\r\n#   modified:   hello.txt\r\n#<\/pre>\n<p id=\"e926\" class=\"graf graf--p graf-after--pre\">Changes to the hello.txt have been staged. This means that git knows about the change, but it is not permanent in the repository. The next commit will include the changes staged.<\/p>\n<p id=\"d4aa\" class=\"graf graf--p graf-after--p\">Should you decide not to commit the change, the status command will remind you that you can use the git reset command to unstage these changes.<\/p>\n<h3 id=\"e461\" class=\"graf graf--h3 graf-after--p\">Staging and committing<\/h3>\n<p id=\"c461\" class=\"graf graf--p graf-after--h3\">A staging step in git allows you to continue making changes to the working directory, and when you decide you wanna interact with version control, it allows you to record changes in small commits.<\/p>\n<p id=\"1732\" class=\"graf graf--p graf-after--p\">Suppose you have edited three files (a. html, b. html, and c. html). After that you need to commit all the changes so that the changes to a. html and b. html were a single commit, while the changes to c. html were not logically associated with the first two files and were done in a separate commit.<\/p>\n<p id=\"4e46\" class=\"graf graf--p graf-after--p\">In theory you can do the following:<\/p>\n<pre id=\"5993\" class=\"graf graf--pre graf-after--p\">touch a.html b.html c.html\r\ngit add a.html\r\ngit add b.html\r\ngit commit -m \"Changes for a and b\"<\/pre>\n<pre id=\"d795\" class=\"graf graf--pre graf-after--pre\">git add c.html\r\ngit commit -m \"Unrelated change to c\"<\/pre>\n<p id=\"48c6\" class=\"graf graf--p graf-after--pre\">Separating staging and committing, you get the chance to easily customize what goes into a commit<\/p>\n<h3 id=\"3f21\" class=\"graf graf--h3 graf-after--p\">8. Committing the\u00a0changes<\/h3>\n<p id=\"4d12\" class=\"graf graf--p graf-after--h3\">Well, enough about staging. Let\u2019s commit the staged changes to the repository.<\/p>\n<p id=\"6b35\" class=\"graf graf--p graf-after--p\">When you previously used git commit for committing the first hello.html version to the repository, you included the -m flag that gives a comment on the command line. The commit command allows interactively editing comments for the commit. And now, let\u2019s see how it works.<\/p>\n<p id=\"90e7\" class=\"graf graf--p graf-after--p\">If you omit the -m flag from the command line, git will pop you into the editor of your choice from the list (in order of priority):<\/p>\n<ul class=\"postList\">\n<li id=\"b31e\" class=\"graf graf--li graf-after--p\">GIT_EDITOR environment variable<\/li>\n<li id=\"d33b\" class=\"graf graf--li graf-after--li\">core.editor configuration setting<\/li>\n<li id=\"b851\" class=\"graf graf--li graf-after--li\">VISUAL environment variable<\/li>\n<li id=\"45fa\" class=\"graf graf--li graf-after--li\">EDITOR environment variable<\/li>\n<\/ul>\n<p id=\"0df4\" class=\"graf graf--p graf-after--li\">I have the EDITOR variable set to emacsclient (available for Linux and Mac).<\/p>\n<p id=\"7fa4\" class=\"graf graf--p graf-after--p\">Let us commit now and check the status.<\/p>\n<h4 id=\"204e\" class=\"graf graf--h4 graf-after--p\">RUN:<\/h4>\n<pre id=\"e4bb\" class=\"graf graf--pre graf-after--h4\">git commit<\/pre>\n<p id=\"6ab2\" class=\"graf graf--p graf-after--pre\">You will see the following in your editor:<\/p>\n<h4 id=\"f715\" class=\"graf graf--h4 graf-after--p\">RESULT:<\/h4>\n<pre id=\"6af3\" class=\"graf graf--pre graf-after--h4\">|\r\n# Please enter the commit message for your changes. Lines starting\r\n# with '#' will be ignored, and an empty message aborts the commit.\r\n# On branch master\r\n# Changes to be committed:\r\n#   (use \"git reset HEAD &lt;file&gt;...\" to unstage)\r\n#\r\n#   modified:   hello.html\r\n#<\/pre>\n<p id=\"258a\" class=\"graf graf--p graf-after--pre\">On the first line, enter the comment: \u201cAdded hi tag\u201d. Save the file and exit the editor (to do it in default editor, press ESC and then type:wq and hit Enter). You should see\u00a0\u2026<\/p>\n<h4 id=\"1d48\" class=\"graf graf--h4 graf-after--p\">RESULT:<\/h4>\n<pre id=\"35f9\" class=\"graf graf--pre graf-after--h4\">git commit\r\nWaiting for Emacs...\r\n[master 569aa96] Added h1 tag\r\n 1 files changed, 1 insertions(+), 1 deletions(-)<\/pre>\n<p id=\"9b3a\" class=\"graf graf--p graf--startsWithDoubleQuote graf-after--pre\">\u201cWaiting for Emacs\u2026\u201d is obtained from the emacsclient program sending the file to a running emacs program and waiting for it to be closed. The rest of the data is the standard commit messages.<\/p>\n<h3 id=\"6507\" class=\"graf graf--h3 graf-after--p\">02Checking the\u00a0status<\/h3>\n<p id=\"4454\" class=\"graf graf--p graf-after--h3\">At the end let us check the status.<\/p>\n<h4 id=\"2b68\" class=\"graf graf--h4 graf-after--p\">RUN:<\/h4>\n<pre id=\"8e24\" class=\"graf graf--pre graf-after--h4\">git status<\/pre>\n<p id=\"f7cb\" class=\"graf graf--p graf-after--pre\">You will see\u00a0\u2026<\/p>\n<h4 id=\"8156\" class=\"graf graf--h4 graf-after--p\">RESULT:<\/h4>\n<pre id=\"8b4d\" class=\"graf graf--pre graf-after--h4\">$ git status\r\n# On branch master\r\nnothing to commit (working directory clean)<\/pre>\n<p id=\"25f1\" class=\"graf graf--p graf-after--pre\">The working directory is clean, you can continue working<\/p>\n<h3 id=\"d251\" class=\"graf graf--h3 graf-after--p\">Changes, not\u00a0files<\/h3>\n<p id=\"b6fe\" class=\"graf graf--p graf-after--h3\">Understanding that git works with the changes, not the files.<\/p>\n<p id=\"92d9\" class=\"graf graf--p graf-after--p\">Most version control systems work with files. You add the file to source control and the system tracks changes from that moment on.<\/p>\n<p id=\"72ef\" class=\"graf graf--p graf-after--p\">Git concentrates on the changes to a file, not the file itself. A git add file command does not tell git to add the file to the repository, but to note the current state of the file for it to be commited later.<\/p>\n<p id=\"6f75\" class=\"graf graf--p graf-after--p\">We will try to investigate the difference in this lesson.<\/p>\n<h3 id=\"286f\" class=\"graf graf--h3 graf-after--p\">First Change:<\/h3>\n<p id=\"3339\" class=\"graf graf--p graf-after--h3\">FILE: HELLO.txt<\/p>\n<pre id=\"d261\" class=\"graf graf--pre graf-after--p\">First Change<\/pre>\n<h3 id=\"8bc8\" class=\"graf graf--h3 graf-after--pre\">Add this\u00a0change<\/h3>\n<p id=\"a5dc\" class=\"graf graf--p graf-after--h3\">Now add this change to the git staging.<\/p>\n<h4 id=\"f941\" class=\"graf graf--h4 graf-after--p\">RUN:<\/h4>\n<pre id=\"fb59\" class=\"graf graf--pre graf-after--h4\">git add hello.html<\/pre>\n<h3 id=\"8266\" class=\"graf graf--h3 graf-after--pre\">Second change:<\/h3>\n<h4 id=\"da52\" class=\"graf graf--h4 graf-after--h3\">FILE: HELLO.txt<\/h4>\n<pre id=\"bc6e\" class=\"graf graf--pre graf-after--h4\">Second Change<\/pre>\n<h3 id=\"8331\" class=\"graf graf--h3 graf-after--pre\">Check the current\u00a0status<\/h3>\n<h4 id=\"c9b9\" class=\"graf graf--h4 graf-after--h3\">RUN:<\/h4>\n<pre id=\"1d9e\" class=\"graf graf--pre graf-after--h4\">git status<\/pre>\n<p id=\"06e0\" class=\"graf graf--p graf-after--pre\">You will see\u00a0\u2026<\/p>\n<h4 id=\"8c2e\" class=\"graf graf--h4 graf-after--p\">RESULT:<\/h4>\n<pre id=\"5e31\" class=\"graf graf--pre graf-after--h4\">$ git status\r\n# On branch master\r\n# Changes to be committed:\r\n#   (use \"git reset HEAD &lt;file&gt;...\" to unstage)\r\n#\r\n#   modified:   hello.txt\r\n#\r\n# Changes not staged for commit:\r\n#   (use \"git add &lt;file&gt;...\" to update what will be committed)\r\n#   (use \"git checkout -- &lt;file&gt;...\" to discard changes in working directory)\r\n#\r\n#   modified:   hello.txt\r\n#<\/pre>\n<p id=\"cd52\" class=\"graf graf--p graf-after--pre\">Please note that hello.txt is listed in the status twice. The first change (the addition of default tags) is staged and ready for a commit. The second change (adding HTML headers) is unstaged. If you were making a commit right now, headers would not have been saved to the repository.<\/p>\n<p id=\"f3a1\" class=\"graf graf--p graf-after--p\">Let\u2019s check.<\/p>\n<h3 id=\"ba22\" class=\"graf graf--h3 graf-after--p\">05Commit<\/h3>\n<p id=\"b89c\" class=\"graf graf--p graf-after--h3\">Commit the staged changes (default values), then check the status one more time.<\/p>\n<h4 id=\"c7b9\" class=\"graf graf--h4 graf-after--p\">RUN:<\/h4>\n<pre id=\"7f5b\" class=\"graf graf--pre graf-after--h4\">git commit -m \"Added second \"\r\ngit status<\/pre>\n<p id=\"c646\" class=\"graf graf--p graf-after--pre\">You will see\u00a0\u2026<\/p>\n<h4 id=\"dccc\" class=\"graf graf--h4 graf-after--p\">RESULT:<\/h4>\n<pre id=\"2db3\" class=\"graf graf--pre graf-after--h4\">$ git commit -m \"Added second\"\r\n[master 8c32287] Added standard HTML page tags\r\n 1 files changed, 3 insertions(+), 1 deletions(-)\r\n$ git status\r\n# On branch master\r\n# Changes not staged for commit:\r\n#   (use \"git add &lt;file&gt;...\" to update what will be committed)\r\n#   (use \"git checkout -- &lt;file&gt;...\" to discard changes in working directory)\r\n#\r\n#   modified:   hello.txt\r\n#\r\nno changes added to commit (use \"git add\" and\/or \"git commit -a\")<\/pre>\n<p id=\"939b\" class=\"graf graf--p graf-after--pre\">The status command suggests that hello.html has unrecorded changes, but is no longer in the buffer zone.<\/p>\n<h3 id=\"8954\" class=\"graf graf--h3 graf-after--p\">Adding the second\u00a0change<\/h3>\n<p id=\"f1f0\" class=\"graf graf--p graf-after--h3\">Add the second change to the staging area, after that run the git status command.<\/p>\n<h4 id=\"9dbc\" class=\"graf graf--h4 graf-after--p\">RUN:<\/h4>\n<pre id=\"104c\" class=\"graf graf--pre graf-after--h4\">git add .\r\ngit status<\/pre>\n<p id=\"fb98\" class=\"graf graf--p graf-after--pre\"><strong class=\"markup--strong markup--p-strong\">Note:<\/strong>\u00a0The current directory (\u2018.\u2019) will be our file to add. This is the most convenient way to add all the changes to the files of the current directory and its folders. But since it adds everything, it is a good idea to check the status prior to doing an add\u00a0., to make sure you don\u2019t add any file that should not be added.<\/p>\n<p id=\"291f\" class=\"graf graf--p graf-after--p\">I wanted you to see the \u201cadd\u00a0.\u201d trick, and we will continue adding explicit files later on just in case.<\/p>\n<p id=\"9758\" class=\"graf graf--p graf-after--p\">You will see\u00a0\u2026<\/p>\n<h4 id=\"fbca\" class=\"graf graf--h4 graf-after--p\">RESULT:<\/h4>\n<pre id=\"fd10\" class=\"graf graf--pre graf-after--h4\">$ git status\r\n# On branch master\r\n# Changes to be committed:\r\n#   (use \"git reset HEAD &lt;file&gt;...\" to unstage)\r\n#\r\n#   modified:   hello.html\r\n#<\/pre>\n<p id=\"c99c\" class=\"graf graf--p graf-after--pre\">The second change has been staged and is ready for a commit.<\/p>\n<h3 id=\"3601\" class=\"graf graf--h3 graf-after--p\">Commit the second\u00a0change<\/h3>\n<h4 id=\"9ef1\" class=\"graf graf--h4 graf-after--h3\">RUN:<\/h4>\n<pre id=\"5ff1\" class=\"graf graf--pre graf-after--h4\">git commit -m \"Added second change\"<\/pre>\n<h3 id=\"1b4f\" class=\"graf graf--h3 graf-after--pre\">History<\/h3>\n<h4 id=\"e27c\" class=\"graf graf--h4 graf-after--h3\">To learn to view the project\u2019s history.<\/h4>\n<p id=\"08d1\" class=\"graf graf--p graf-after--h4\">Getting a list of changes made is a function of the git log command.<\/p>\n<h4 id=\"a138\" class=\"graf graf--h4 graf-after--p\">RUN:<\/h4>\n<pre id=\"3319\" class=\"graf graf--pre graf-after--h4\">git log<\/pre>\n<p id=\"5214\" class=\"graf graf--p graf-after--pre\">You will see\u00a0\u2026<\/p>\n<h4 id=\"1749\" class=\"graf graf--h4 graf-after--p\">RESULT:<\/h4>\n<p id=\"38fb\" class=\"graf graf--p graf-after--h4\">commit ef44671e9b7aef27027f9d2b438e366d3133102b<br \/>\nAuthor: Aravind G V &lt;<a class=\"markup--anchor markup--p-anchor\" href=\"mailto:aravind_g@intuit.com\" target=\"_blank\" rel=\"nofollow noopener\" data-href=\"mailto:aravind_g@intuit.com\">aravind_g@<\/a>?\u2014?\u2014 &gt;<br \/>\nDate: Wed Apr 6 13:09:55 2016 +0530<\/p>\n<p id=\"a08d\" class=\"graf graf--p graf-after--p\">XIADMIN windows scripts<\/p>\n<p id=\"2491\" class=\"graf graf--p graf-after--p\">commit 70d87e94e7937f8a6ce89d4cd6001d99abfb4e77<br \/>\nAuthor: Neelam Malik &lt;<a class=\"markup--anchor markup--p-anchor\" href=\"mailto:Neelam_Malik@intuit.com\" target=\"_blank\" rel=\"nofollow noopener\" data-href=\"mailto:Neelam_Malik@intuit.com\">Neelam_Malik@<\/a>?\u2014?&gt;<br \/>\nDate: Wed Apr 6 11:21:54 2016 +0530<\/p>\n<p id=\"852b\" class=\"graf graf--p graf-after--p\">added app_stop<\/p>\n<p id=\"f404\" class=\"graf graf--p graf-after--p\">commit 77ac1140018714a6b26c27535c6279eff40c87e9<br \/>\nAuthor: Neelam Malik &lt;<a class=\"markup--anchor markup--p-anchor\" href=\"mailto:Neelam_Malik@intuit.com\" target=\"_blank\" rel=\"nofollow noopener\" data-href=\"mailto:Neelam_Malik@intuit.com\">aravind_gv@<\/a>?\u2014?&gt;<br \/>\nDate: Wed Apr 6 11:21:32 2016 +0530<\/p>\n<p id=\"1d5b\" class=\"graf graf--p graf-after--p\">added app_status<\/p>\n<p id=\"313e\" class=\"graf graf--p graf-after--p\">commit 36fb85091deabfe3e590a101aa1a1aca1adfa8c2<br \/>\nAuthor: Neelam Malik ?<a class=\"markup--anchor markup--p-anchor\" href=\"mailto:Neelam_Malik@intuit.com\" target=\"_blank\" rel=\"nofollow noopener\" data-href=\"mailto:Neelam_Malik@intuit.com\">@?\u2014?.om<\/a>&gt;<br \/>\nDate: Wed Apr 6 11:21:04 2016 +0530<\/p>\n<p id=\"4963\" class=\"graf graf--p graf-after--p\">added app_start<\/p>\n<p id=\"4b77\" class=\"graf graf--p graf-after--p\">added app_stop<\/p>\n<p id=\"f803\" class=\"graf graf--p graf-after--p\">commit e4be69a36c3a37203e2b539f97eb77b3f253fe99<br \/>\nAuthor: Neelam Malik &lt;<a class=\"markup--anchor markup--p-anchor\" href=\"mailto:Neelam_Malik@intuit.com\" target=\"_blank\" rel=\"nofollow noopener\" data-href=\"mailto:Neelam_Malik@intuit.com\">aravind_gv@<\/a>?\u2014?&gt;<br \/>\nDate: Wed Apr 6 11:18:42 2016 +0530<\/p>\n<h3 id=\"af5b\" class=\"graf graf--h3 graf-after--p\">One line\u00a0history<\/h3>\n<p id=\"ac8e\" class=\"graf graf--p graf-after--h3\">You fully control over what the log shows. I like the single line format:<\/p>\n<h4 id=\"f888\" class=\"graf graf--h4 graf-after--p\">RUN:<\/h4>\n<pre id=\"a338\" class=\"graf graf--pre graf-after--h4\">git log --pretty=oneline<\/pre>\n<p id=\"3dcc\" class=\"graf graf--p graf-after--pre\">You will see\u00a0\u2026<\/p>\n<h4 id=\"fa92\" class=\"graf graf--h4 graf-after--p\">RESULT:<\/h4>\n<pre id=\"4e57\" class=\"graf graf--pre graf-after--h4\">$ git log --pretty=oneline\r\nfa3c1411aa09441695a9e645d4371e8d749da1dc Added HTML header\r\n8c3228730ed03116815a5cc682e8105e7d981928 Added standard HTML page tags\r\n43628f779cb333dd30d78186499f93638107f70b Added h1 tag\r\n911e8c91caeab8d30ad16d56746cbd6eef72dc4c First Commit<\/pre>\n<h3 id=\"73d6\" class=\"graf graf--h3 graf-after--pre\">Controlling the display of\u00a0entries<\/h3>\n<p id=\"667d\" class=\"graf graf--p graf-after--h3\">There are many options to choose which entries appear in the log. Play around with the following parameters:<\/p>\n<pre id=\"57e1\" class=\"graf graf--pre graf-after--p\">git log --pretty=oneline --max-count=2\r\ngit log --pretty=oneline --since='5 minutes ago'\r\ngit log --pretty=oneline --until='5 minutes ago'\r\ngit log --pretty=oneline --author=&lt;your name&gt;\r\ngit log --pretty=oneline --all<\/pre>\n<p id=\"0df5\" class=\"graf graf--p graf-after--pre\">Details are provided in the git-log instruction.<\/p>\n<h3 id=\"8df0\" class=\"graf graf--h3 graf-after--p\">Getting fancy<\/h3>\n<p id=\"10a5\" class=\"graf graf--p graf-after--h3\">This is what I use to review the changes made within the last week. I will add?\u2014?author=alex if I want to see only the changes made by me.<\/p>\n<pre id=\"e4a1\" class=\"graf graf--pre graf-after--p\">git log --all --pretty=format:\"%h %cd %s (%an)\" --since='7 days ago'<\/pre>\n<h3 id=\"cb03\" class=\"graf graf--h3 graf-after--pre\">The ultimate format of the\u00a0log<\/h3>\n<p id=\"0f1f\" class=\"graf graf--p graf-after--h3\">Over time, I found the following log format to be the most suitable.<\/p>\n<h4 id=\"711f\" class=\"graf graf--h4 graf-after--p\">RUN:<\/h4>\n<pre id=\"fb57\" class=\"graf graf--pre graf-after--h4\">git log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short<\/pre>\n<p id=\"cfb1\" class=\"graf graf--p graf-after--pre\">It looks like this:<\/p>\n<h4 id=\"b02c\" class=\"graf graf--h4 graf-after--p\">RESULT:<\/h4>\n<pre id=\"1479\" class=\"graf graf--pre graf-after--h4\">$ git log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short\r\n* fa3c141 2011-03-09 | Added HTML header (HEAD, master) [Alexander Shvets]\r\n* 8c32287 2011-03-09 | Added standard HTML page tags [Alexander Shvets]\r\n* 43628f7 2011-03-09 | Added h1 tag [Alexander Shvets]\r\n* 911e8c9 2011-03-09 | First Commit [Alexander Shvets]<\/pre>\n<p id=\"a017\" class=\"graf graf--p graf-after--pre\">Let\u2019s look at it in detail:<\/p>\n<ul class=\"postList\">\n<li id=\"4566\" class=\"graf graf--li graf-after--p\">\u2014 pretty=\u201d\u2026\u201d defines the output format.<\/li>\n<li id=\"59e9\" class=\"graf graf--li graf-after--li\">%h is the abbreviated hash of the commit<\/li>\n<li id=\"e5d7\" class=\"graf graf--li graf-after--li\">%d commit decorations (e.g. branch heads or tags)<\/li>\n<li id=\"773f\" class=\"graf graf--li graf-after--li\">%ad is the commit date<\/li>\n<li id=\"3f2a\" class=\"graf graf--li graf-after--li\">%s is the comment<\/li>\n<li id=\"d9b9\" class=\"graf graf--li graf-after--li\">%an is the name of the author<\/li>\n<li id=\"92ff\" class=\"graf graf--li graf-after--li\">\u2014 graph tells git to display the commit tree in the form of an ASCII graph layout<\/li>\n<li id=\"fc7c\" class=\"graf graf--li graf-after--li\">\u2014 date=short keeps the date format short and nice<\/li>\n<\/ul>\n<p id=\"a7b6\" class=\"graf graf--p graf-after--li\">So, every time you want to see a log, you\u2019ll have to do a lot of typing. Fortunately, we will find out about the git aliases in the next lesson.<\/p>\n<h3 id=\"86ab\" class=\"graf graf--h3 graf-after--p\">Other tools<\/h3>\n<p id=\"1eb2\" class=\"graf graf--p graf-after--h3\">Both gitx (for Mac) and gitk (for any platform) can help to explore log history.<\/p>\n<h3 id=\"b2fb\" class=\"graf graf--h3 graf-after--p\">Aliases<\/h3>\n<h4 id=\"51ac\" class=\"graf graf--h4 graf-after--h3\">Command aliases (optional)<\/h4>\n<h3 id=\"12e6\" class=\"graf graf--h3 graf-after--h4\">Common aliases<\/h3>\n<p id=\"ec06\" class=\"graf graf--p graf-after--h3\">For Windows users:<\/p>\n<h4 id=\"0e3c\" class=\"graf graf--h4 graf-after--p\">RUN:<\/h4>\n<pre id=\"8719\" class=\"graf graf--pre graf-after--h4\">git config --global alias.co checkout\r\ngit config --global alias.ci commit\r\ngit config --global alias.st status\r\ngit config --global alias.br branch\r\ngit config --global alias.hist 'log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short'\r\ngit config --global alias.type 'cat-file -t'\r\ngit config --global alias.dump 'cat-file -p'<\/pre>\n<p id=\"8c68\" class=\"graf graf--p graf-after--pre\">Also, for users of Unix\/Mac:<\/p>\n<p id=\"35a8\" class=\"graf graf--p graf-after--p\">git status, git add, git commit, and git checkout are common commands so it is a good idea to have abbreviations for them.<\/p>\n<p id=\"f05b\" class=\"graf graf--p graf-after--p\">Add the following to the\u00a0.gitconfig file in your $HOME directory.<\/p>\n<h4 id=\"5b80\" class=\"graf graf--h4 graf-after--p\">.GITCONFIG<\/h4>\n<pre id=\"cdbf\" class=\"graf graf--pre graf-after--h4\">[alias]\r\n  co = checkout\r\n  ci = commit\r\n  st = status\r\n  br = branch\r\n  hist = log --pretty=format:\\\"%h %ad | %s%d [%an]\\\" --graph --date=short\r\n  type = cat-file -t\r\n  dump = cat-file -p<\/pre>\n<p id=\"0a7d\" class=\"graf graf--p graf-after--pre\">We\u2019ve already talked about commit and status commands. In the previous lesson we covered the log command and will get to know the checkout command very soon. The most important thing to learn from this lesson is that you can type git st wherever you had to typegit status. Best of all, the git hist command will help you avoid the really long log command.<\/p>\n<p id=\"de3d\" class=\"graf graf--p graf-after--p\">Go ahead and try using the new commands.<\/p>\n<p id=\"e6bc\" class=\"graf graf--p graf-after--p\">If your shell supports aliases, or shortcuts, you can add aliases on this level, too. I use:<\/p>\n<pre id=\"7271\" class=\"graf graf--pre graf-after--p\">alias gs='git status '\r\nalias ga='git add '\r\nalias gb='git branch '\r\nalias gc='git commit'\r\nalias gd='git diff'\r\nalias go='git checkout '\r\nalias gk='gitk --all&amp;'\r\nalias gx='gitx --all'<\/pre>\n<pre id=\"9c0f\" class=\"graf graf--pre graf-after--pre\">alias got='git '\r\nalias get='git '<\/pre>\n<p id=\"efa5\" class=\"graf graf--p graf-after--pre\">The go abbreviation for git checkout is very useful, allowing me to type:<\/p>\n<pre id=\"3479\" class=\"graf graf--pre graf-after--p\">go &lt;branch&gt;<\/pre>\n<p id=\"19d1\" class=\"graf graf--p graf-after--pre\">to checkout a particular branch.<\/p>\n<p id=\"66c4\" class=\"graf graf--p graf-after--p\">Also, I often mistype git as get or got so I created aliases for them too.<\/p>\n<h3 id=\"511d\" class=\"graf graf--h3 graf-after--p\">Getting older\u00a0versions<\/h3>\n<p id=\"4512\" class=\"graf graf--p graf-after--h3\">To learn how to checkout any previous snapshot into the working directory.<\/p>\n<p id=\"dc61\" class=\"graf graf--p graf-after--p\">Going back in history is very simple. The checkout command can copy any snapshot from the repo to the working directory.<\/p>\n<h3 id=\"dbed\" class=\"graf graf--h3 graf-after--p\">Getting hashes for the previous\u00a0versions<\/h3>\n<h4 id=\"e2c1\" class=\"graf graf--h4 graf-after--h3\">RUN:<\/h4>\n<pre id=\"33d0\" class=\"graf graf--pre graf-after--h4\">git hist<\/pre>\n<p id=\"999c\" class=\"graf graf--p graf-after--pre\"><strong class=\"markup--strong markup--p-strong\">Note:<\/strong>\u00a0Do not forget to define hist in your\u00a0.gitconfig file? If you do not remember how, review the lesson on aliases.<\/p>\n<h4 id=\"da28\" class=\"graf graf--h4 graf-after--p\">RESULT:<\/h4>\n<pre id=\"f50e\" class=\"graf graf--pre graf-after--h4\">$ git hist\r\n* 7358571 2016-06-23 | Second Test (HEAD -&gt; master) [Aravind G V]\r\n* 2fc4372 2016-06-23 | First Commit [Aravind G V]<\/pre>\n<p id=\"8a04\" class=\"graf graf--p graf-after--pre\">Check the log data and find the hash for the first commit. You will find it in the last line of the git hist data. Use the code (its first 7 chars are enough) in the command below. After that check the contents of the hello.html file.<\/p>\n<h4 id=\"9743\" class=\"graf graf--h4 graf-after--p\">RUN:<\/h4>\n<pre id=\"a00c\" class=\"graf graf--pre graf-after--h4\">git checkout &lt;hash&gt;\r\ncat hello.txt<\/pre>\n<p id=\"e5fd\" class=\"graf graf--p graf-after--pre\"><strong class=\"markup--strong markup--p-strong\">Note:<\/strong>\u00a0Many commands depend on the hash values in the repository. Since my hash values will be different from yours, substitute in the appropriate hash value for your repository everytime you see &lt;hash&gt; or &lt;treehash&gt; in the command.<\/p>\n<p id=\"058f\" class=\"graf graf--p graf-after--p\">You will see\u00a0\u2026<\/p>\n<h4 id=\"a31a\" class=\"graf graf--h4 graf-after--p\">RESULT:<\/h4>\n<pre id=\"0e49\" class=\"graf graf--pre graf-after--h4\">$ git checkout 911e8c9\r\nNote: checking out '911e8c9'.<\/pre>\n<pre id=\"7a72\" class=\"graf graf--pre graf-after--pre\">You are in 'detached HEAD' state. You can look around, make experimental\r\nchanges and commit them, and you can discard any commits you make in this\r\nstate without impacting any branches by performing another checkout.<\/pre>\n<pre id=\"9f9e\" class=\"graf graf--pre graf-after--pre\">If you want to create a new branch to retain commits you create, you may\r\ndo so (now or later) by using -b with the checkout command again. Example:<\/pre>\n<pre id=\"d88b\" class=\"graf graf--pre graf-after--pre\">  git checkout -b new_branch_name<\/pre>\n<pre id=\"9b19\" class=\"graf graf--pre graf-after--pre\">HEAD is now at 911e8c9... First Commit\r\n$ cat hello.txt\r\nHello, World<\/pre>\n<p id=\"f44b\" class=\"graf graf--p graf-after--pre\">The checkout command output totally clarifies the situation. Older git versions will complain about not being on a local branch. But you don\u2019t need to worry about that right now.<\/p>\n<p id=\"7977\" class=\"graf graf--p graf-after--p\">Note that the content of the hello.html file is the default content.<\/p>\n<h3 id=\"234b\" class=\"graf graf--h3 graf-after--p\">Returning to the latest version in the master\u00a0branch<\/h3>\n<h4 id=\"c7a2\" class=\"graf graf--h4 graf-after--h3\">RUN:<\/h4>\n<pre id=\"f63c\" class=\"graf graf--pre graf-after--h4\">git checkout master\r\ncat hello.txt<\/pre>\n<p id=\"8a8e\" class=\"graf graf--p graf--startsWithSingleQuote graf-after--pre\">\u2018master\u2019 is the name of the default branch. By checking out a branch by name, you go to its latest version.<\/p>\n<h3 id=\"c5a7\" class=\"graf graf--h3 graf-after--p\">Tagging versions<\/h3>\n<p id=\"997e\" class=\"graf graf--p graf-after--h3\">To learn how to tag commits for future references<\/p>\n<p id=\"5b59\" class=\"graf graf--p graf-after--p\">Let\u2019s call the current version of the hello program version 1 (v1).<\/p>\n<h3 id=\"6156\" class=\"graf graf--h3 graf-after--p\">Creating a tag of the\u00a0first<\/h3>\n<h4 id=\"1a67\" class=\"graf graf--h4 graf-after--h3\">RUN:<\/h4>\n<pre id=\"c98f\" class=\"graf graf--pre graf-after--h4\">git tag v1<\/pre>\n<p id=\"0092\" class=\"graf graf--p graf-after--pre\">Now, the current version of the page is referred to as\u00a0<em class=\"markup--em markup--p-em\">v1<\/em>.<\/p>\n<h3 id=\"3d73\" class=\"graf graf--h3 graf-after--p\">Tags for previous\u00a0versions<\/h3>\n<p id=\"1afa\" class=\"graf graf--p graf-after--h3\">Let\u2019s tag the version prior to the current version with the name v1-beta. First of all we will checkout the previous version. Instead of looking up the hash, we are going to use the ^ notation indicating \u201cthe parent of v1\u201d.<\/p>\n<p id=\"d4ae\" class=\"graf graf--p graf-after--p\">If the v1^ notation causes troubles, try using v1~1, referencing the same version. This notation means \u201cthe first version prior to v1\u201d.<\/p>\n<h4 id=\"cbd8\" class=\"graf graf--h4 graf-after--p\">RUN:<\/h4>\n<pre id=\"4397\" class=\"graf graf--pre graf-after--h4\">git checkout v1^\r\ncat hello.html<\/pre>\n<h4 id=\"31fd\" class=\"graf graf--h4 graf-after--pre\">RUN:<\/h4>\n<pre id=\"b12a\" class=\"graf graf--pre graf-after--h4\">$ git checkout v1^\r\nNote: checking out 'v1^'.<\/pre>\n<pre id=\"86c4\" class=\"graf graf--pre graf-after--pre\">You are in 'detached HEAD' state. You can look around, make experimental\r\nchanges and commit them, and you can discard any commits you make in this\r\nstate without impacting any branches by performing another checkout.<\/pre>\n<pre id=\"9f25\" class=\"graf graf--pre graf-after--pre\">If you want to create a new branch to retain commits you create, you may\r\ndo so (now or later) by using -b with the checkout command again. Example:<\/pre>\n<pre id=\"3f5d\" class=\"graf graf--pre graf-after--pre\">  git checkout -b new_branch_name<\/pre>\n<pre id=\"dfc8\" class=\"graf graf--pre graf-after--pre\">HEAD is now at 8c32287... Added standard HTML page tags\r\n$ cat hello.html\r\n\r\n<\/pre>\n<p id=\"2f1e\" class=\"graf graf--p graf-after--pre\">.<\/p>\n<h4 id=\"effa\" class=\"graf graf--h4 graf-after--p\">RUN:<\/h4>\n<pre id=\"a98e\" class=\"graf graf--pre graf-after--h4\">git tag v1-beta<\/pre>\n<h3 id=\"c298\" class=\"graf graf--h3 graf-after--pre\">Check out by the tag\u00a0name<\/h3>\n<p id=\"c852\" class=\"graf graf--p graf-after--h3\">Now try to checkout between the two tagged versions.<\/p>\n<h4 id=\"b6fd\" class=\"graf graf--h4 graf-after--p\">RUN:<\/h4>\n<pre id=\"67a7\" class=\"graf graf--pre graf-after--h4\">git checkout v1\r\ngit checkout v1-beta<\/pre>\n<h4 id=\"aff5\" class=\"graf graf--h4 graf-after--pre\">RESULT:<\/h4>\n<pre id=\"888a\" class=\"graf graf--pre graf-after--h4\">$ git checkout v1\r\nPrevious HEAD position was 8c32287... Added standard HTML page tags\r\nHEAD is now at fa3c141... Added HTML header\r\n$ git checkout v1-beta\r\nPrevious HEAD position was fa3c141... Added HTML header\r\nHEAD is now at 8c32287... Added standard HTML page tags<\/pre>\n<h3 id=\"f1be\" class=\"graf graf--h3 graf-after--pre\">04Viewing tags with the tag\u00a0command<\/h3>\n<p id=\"a55a\" class=\"graf graf--p graf-after--h3\">You can see the available tags using the git tag command.<\/p>\n<h4 id=\"40d5\" class=\"graf graf--h4 graf-after--p\">RUN:<\/h4>\n<pre id=\"2aaa\" class=\"graf graf--pre graf-after--h4\">git tag<\/pre>\n<h4 id=\"2221\" class=\"graf graf--h4 graf-after--pre\">RESULT:<\/h4>\n<pre id=\"80fa\" class=\"graf graf--pre graf-after--h4\">$ git tag\r\nv1\r\nv1-beta<\/pre>\n<h3 id=\"b918\" class=\"graf graf--h3 graf-after--pre\">Viewing tags in\u00a0logs<\/h3>\n<p id=\"f91d\" class=\"graf graf--p graf-after--h3\">You can also check for tags in the log.<\/p>\n<h4 id=\"6db0\" class=\"graf graf--h4 graf-after--p\">RUN:<\/h4>\n<pre id=\"153f\" class=\"graf graf--pre graf-after--h4\">git hist master --all<\/pre>\n<h4 id=\"2055\" class=\"graf graf--h4 graf-after--pre\">RESULT:<\/h4>\n<pre id=\"2d19\" class=\"graf graf--pre graf-after--h4\">$ git hist master --all\r\n* fa3c141 2011-03-09 | Added HTML header (v1, master) [Alexander Shvets]\r\n* 8c32287 2011-03-09 | Added standard HTML page tags (HEAD, v1-beta) [Alexander Shvets]\r\n* 43628f7 2011-03-09 | Added h1 tag [Alexander Shvets]\r\n* 911e8c9 2011-03-09 | First Commit [Alexander Shvets]<\/pre>\n<p id=\"e871\" class=\"graf graf--p graf-after--pre\">You can see tags (v1 and v1-beta) listed in the log together with the name of the branch (master). The HEAD shows the commit you checked out (currently v1-beta).<\/p>\n<h3 id=\"bfba\" class=\"graf graf--h3 graf-after--p\">Discarding local changes (before\u00a0staging)<\/h3>\n<p id=\"d3a6\" class=\"graf graf--p graf-after--h3\">To learn how to discard the working directory changes<\/p>\n<h3 id=\"48a3\" class=\"graf graf--h3 graf-after--p\">Checking out the Master\u00a0branch<\/h3>\n<p id=\"a54e\" class=\"graf graf--p graf-after--h3\">Make sure you are on the lastest commit in the master brach before you continue.<\/p>\n<h4 id=\"46a8\" class=\"graf graf--h4 graf-after--p\">RUN:<\/h4>\n<pre id=\"7dc8\" class=\"graf graf--pre graf-after--h4\">git checkout master<\/pre>\n<h3 id=\"6697\" class=\"graf graf--h3 graf-after--pre\">Change hello.txt<\/h3>\n<p id=\"d70e\" class=\"graf graf--p graf-after--h3\">It happens that you modify a file in your local working directory and sometimes wish just to discard the committed changes. Here is when the checkout command will help you.<\/p>\n<p id=\"f610\" class=\"graf graf--p graf-after--p\">Make changes to the hello.html file in the form of an unwanted comment.<\/p>\n<h4 id=\"5a5b\" class=\"graf graf--h4 graf-after--p\">FILE: HELLO.txt<\/h4>\n<pre id=\"9de1\" class=\"graf graf--pre graf-after--h4\">test-1\r\ntest-2\r\nno need of this line<\/pre>\n<h3 id=\"e856\" class=\"graf graf--h3 graf-after--pre\">Check the\u00a0status<\/h3>\n<p id=\"9a7f\" class=\"graf graf--p graf-after--h3\">First of all, check the working directory\u2019s status.<\/p>\n<h4 id=\"49ba\" class=\"graf graf--h4 graf-after--p\">RUN:<\/h4>\n<pre id=\"ce82\" class=\"graf graf--pre graf-after--h4\">git status<\/pre>\n<h3 id=\"c912\" class=\"graf graf--h3 graf-after--pre\">Undoing the changes in the working directory<\/h3>\n<p id=\"21c1\" class=\"graf graf--p graf-after--h3\">Use the checkout command in order to checkout the repository\u2019s version of the hello.html file.<\/p>\n<h4 id=\"bf70\" class=\"graf graf--h4 graf-after--p\">RUN:<\/h4>\n<pre id=\"d2e5\" class=\"graf graf--pre graf-after--h4\">git checkout hello.txt\r\ngit status\r\ncat hello.txt<\/pre>\n<h3 id=\"8507\" class=\"graf graf--h3 graf-after--pre\">Cancel Staged changes (before committing)<\/h3>\n<p id=\"add3\" class=\"graf graf--p graf-after--h3\">To learn how to undo changes that have been staged<\/p>\n<h3 id=\"3218\" class=\"graf graf--h3 graf-after--p\">Edit file and stage\u00a0changes<\/h3>\n<p id=\"b95d\" class=\"graf graf--p graf-after--h3\">Make changes to the hello.html file in the form of an unwanted comment<\/p>\n<h4 id=\"f13a\" class=\"graf graf--h4 graf-after--p\">FILE: HELLO.txt<\/h4>\n<pre id=\"e3f6\" class=\"graf graf--pre graf-after--h4\">test-1\r\ntest-2\r\nno need of this line<\/pre>\n<p id=\"b30b\" class=\"graf graf--p graf-after--pre\">Stage the modified file.<\/p>\n<h4 id=\"779a\" class=\"graf graf--h4 graf-after--p\">RUN:<\/h4>\n<pre id=\"f622\" class=\"graf graf--pre graf-after--h4\">git add hello.txt<\/pre>\n<h3 id=\"c647\" class=\"graf graf--h3 graf-after--pre\">Check the\u00a0status<\/h3>\n<p id=\"4645\" class=\"graf graf--p graf-after--h3\">Check the status of unwanted changes\u00a0.<\/p>\n<h4 id=\"746c\" class=\"graf graf--h4 graf-after--p\">RUN:<\/h4>\n<pre id=\"14de\" class=\"graf graf--pre graf-after--h4\">git status<\/pre>\n<h4 id=\"fa38\" class=\"graf graf--h4 graf-after--pre\">RESULT:<\/h4>\n<pre id=\"905e\" class=\"graf graf--pre graf-after--h4\">$ git status\r\n# On branch master\r\n# Changes to be committed:\r\n#   (use \"git reset HEAD &lt;file&gt;...\" to unstage)\r\n#\r\n#   modified:   hello.txt\r\n#<\/pre>\n<p id=\"1a8d\" class=\"graf graf--p graf-after--pre\">Status shows that the change has been staged and is ready to commit.<\/p>\n<h3 id=\"e5a3\" class=\"graf graf--h3 graf-after--p\">Reset the buffer\u00a0zone<\/h3>\n<p id=\"d88a\" class=\"graf graf--p graf-after--h3\">Fortunately, the displayed status shows us exactly what we should do to cancel staged changes.<\/p>\n<h4 id=\"7de5\" class=\"graf graf--h4 graf-after--p\">RUN:<\/h4>\n<pre id=\"26be\" class=\"graf graf--pre graf-after--h4\">git reset HEAD hello.txt<\/pre>\n<h4 id=\"284f\" class=\"graf graf--h4 graf-after--pre\">RESULT:<\/h4>\n<pre id=\"21ba\" class=\"graf graf--pre graf-after--h4\">$ git reset HEAD hello.html\r\nUnstaged changes after reset:\r\nM   hello.html<\/pre>\n<p id=\"f7e2\" class=\"graf graf--p graf-after--pre\">The reset command resets the buffer zone to HEAD. This clears the buffer zone from the changes that we have just staged.<\/p>\n<p id=\"2501\" class=\"graf graf--p graf-after--p\">The reset command (default) does not change the working directory. Therefore, the working directory still contains unwanted comments. We can use the checkout command from the previous tutorial to remove unwanted changes from working directory.<\/p>\n<h3 id=\"d19f\" class=\"graf graf--h3 graf-after--p\">Switch to commit\u00a0version<\/h3>\n<h4 id=\"a20f\" class=\"graf graf--h4 graf-after--h3\">RUN:<\/h4>\n<pre id=\"5089\" class=\"graf graf--pre graf-after--h4\">git checkout hello.html\r\ngit status<\/pre>\n<h4 id=\"90dd\" class=\"graf graf--h4 graf-after--pre\">RESULT:<\/h4>\n<pre id=\"26dd\" class=\"graf graf--pre graf-after--h4\">$ git status\r\n# On branch master\r\nnothing to commit (working directory clean)<\/pre>\n<p id=\"cfff\" class=\"graf graf--p graf-after--pre\">Our working directory is clean again.<\/p>\n<h3 id=\"aa37\" class=\"graf graf--h3 graf-after--p\">Removing a commit from a\u00a0branch<\/h3>\n<p id=\"c19e\" class=\"graf graf--p graf-after--h3\">To learn to delete the branch\u2019s latest commits<\/p>\n<p id=\"d73e\" class=\"graf graf--p graf-after--p\">Revert is a powerful command of the previous section that allows you to cancel any commits to the repository. However, both original and cancelled commits are seen in the history of the branch (when using git log command).<\/p>\n<p id=\"d210\" class=\"graf graf--p graf-after--p\">Often after commit is already made, we realize that it was a mistake. It would be nice to have undo option command allowing deleting incorrect commit immediately. This command would prevent the appearance of unwanted commit in the git log history.<\/p>\n<h3 id=\"215e\" class=\"graf graf--h3 graf-after--p\">The reset\u00a0command<\/h3>\n<p id=\"6f25\" class=\"graf graf--p graf-after--h3\">We have already used reset command to match the buffer zone and the selected commit (HEAD commit was used in the previous lesson).<\/p>\n<p id=\"e7e9\" class=\"graf graf--p graf-after--p\">When a commit reference is given (ie, a branch, hash, or tag name), the reset command will\u2026<\/p>\n<ol class=\"postList\">\n<li id=\"feff\" class=\"graf graf--li graf-after--p\">Overwrite the current branch so it will point to the correct commit<\/li>\n<li id=\"603b\" class=\"graf graf--li graf-after--li\">Optionally reset the buffer zone so it will comply with the specified commit<\/li>\n<li id=\"bf5a\" class=\"graf graf--li graf-after--li\">Optionally reset the working directory so it will match the specified commit<\/li>\n<\/ol>\n<h3 id=\"7854\" class=\"graf graf--h3 graf-after--li\">02Check our\u00a0history<\/h3>\n<p id=\"011e\" class=\"graf graf--p graf-after--h3\">Let us do a quick scan of our commit history.<\/p>\n<h4 id=\"c247\" class=\"graf graf--h4 graf-after--p\">RUN:<\/h4>\n<pre id=\"eb90\" class=\"graf graf--pre graf-after--h4\">git hist<\/pre>\n<h4 id=\"a268\" class=\"graf graf--h4 graf-after--pre\">We see that the last two commits in this branch are \u201cOops\u201d and \u201cRevert Oops\u201d. Let us remove them with reset\u00a0command.<\/h4>\n<h3 id=\"88d7\" class=\"graf graf--h3 graf-after--h4\">Mark this branch\u00a0first<\/h3>\n<p id=\"9254\" class=\"graf graf--p graf-after--h3\">Let us mark the last commit with tag, so you can find it after removing commits.<\/p>\n<h4 id=\"4567\" class=\"graf graf--h4 graf-after--p\">RUN:<\/h4>\n<pre id=\"4fe3\" class=\"graf graf--pre graf-after--h4\">git tag oops<\/pre>\n<h3 id=\"920d\" class=\"graf graf--h3 graf-after--pre\">Reset commit to previous\u00a0Oops<\/h3>\n<p id=\"9b14\" class=\"graf graf--p graf-after--h3\">At the history log (see above), the commit tagged \u00abv1\u00bb is committing previous wrong commit. Let us reset the branch to that point. As the branch has a tag, we can use the tag name in the reset command (if it does not have a tag, we can use the hash value).<\/p>\n<h4 id=\"eefa\" class=\"graf graf--h4 graf-after--p\">RUN:<\/h4>\n<pre id=\"2f19\" class=\"graf graf--pre graf-after--h4\">git reset --hard v1\r\ngit hist<\/pre>\n<h4 id=\"78f8\" class=\"graf graf--h4 graf-after--pre\">RESULT:<\/h4>\n<pre id=\"5807\" class=\"graf graf--pre graf-after--h4\">$ git reset --hard v1\r\nHEAD is now at fa3c141 Added HTML header<\/pre>\n<p id=\"910b\" class=\"graf graf--p graf-after--pre\">Our master branch is pointing at commit v1 and \u201cRevert Oops\u201d and \u201cOops\u201d commits no longer exist in the branch. The?\u2014?hard parameter points out that the working directory must be updated to reflect the new branch head.<\/p>\n<h3 id=\"4067\" class=\"graf graf--h3 graf-after--p\">Nothing is ever\u00a0lost<\/h3>\n<p id=\"3f97\" class=\"graf graf--p graf-after--h3\">What happens to the wrong commits? They are still in the repository. Actually, we still can refer to them. At the beginning of the lesson, we created \u00aboops\u00bb tag for the canceled commit. Let us take a look at\u00a0<em class=\"markup--em markup--p-em\">all<\/em>\u00a0commits.<\/p>\n<h4 id=\"6157\" class=\"graf graf--h4 graf-after--p\">RUN:<\/h4>\n<pre id=\"2dc0\" class=\"graf graf--pre graf-after--h4\">git hist --all<\/pre>\n<p id=\"5c7e\" class=\"graf graf--p graf-after--pre\">We can see that the wrong commits haven\u2019t gone. They are not listed in the master branch anymore but still remain in the repository. They would be still in the repository if we did not tag them, but then we could reference them only by their hash names. Unreferenced commits remain in the repository until the garbage collection software is run by system.<\/p>\n<h3 id=\"3711\" class=\"graf graf--h3 graf-after--p\">Reset dangers<\/h3>\n<p id=\"228f\" class=\"graf graf--p graf-after--h3\">Resets on local branches are usually harmless. The consequences of any \u201caccident\u201d can be reverted by using the proper commit.<\/p>\n<p id=\"44ea\" class=\"graf graf--p graf-after--p\">Though, other users sharing the branch can be confused if the branch is shared on remote repositories.<\/p>\n<h3 id=\"efca\" class=\"graf graf--h3 graf-after--p\">Removing the\u00a0tag<\/h3>\n<p id=\"ec78\" class=\"graf graf--p graf-after--h3\">Oops tag has performed it\u2019s function. Let us remove that tag and permit the garbage collector to delete referenced commit.<\/p>\n<h4 id=\"8e05\" class=\"graf graf--h4 graf-after--p\">RUN:<\/h4>\n<pre id=\"ecbe\" class=\"graf graf--pre graf-after--h4\">git tag -d oops\r\ngit hist --all<\/pre>\n<h3 id=\"4dff\" class=\"graf graf--h3 graf-after--pre\">Changing commits<\/h3>\n<h3 id=\"f3ca\" class=\"graf graf--h3 graf-after--h3\">Goals<\/h3>\n<ul class=\"postList\">\n<li id=\"06c1\" class=\"graf graf--li graf-after--h3\">To learn how to modify an already existing commit<\/li>\n<\/ul>\n<h3 id=\"016e\" class=\"graf graf--h3 graf-after--li\">Change the page and\u00a0commit<\/h3>\n<p id=\"2c50\" class=\"graf graf--p graf-after--h3\">Post an author comment on the page.<\/p>\n<pre id=\"1ef1\" class=\"graf graf--pre graf-after--p\">git add hello.html\r\ngit commit -m \"Add an author comment\"<\/pre>\n<h3 id=\"afdf\" class=\"graf graf--h3 graf-after--pre\">Change the previous\u00a0commit<\/h3>\n<p id=\"3347\" class=\"graf graf--p graf-after--h3\">We do not want to create another commit for some update. Let us change the previous commit and add an update.<\/p>\n<pre id=\"51a1\" class=\"graf graf--pre graf-after--p\">git add hello.html\r\ngit commit --amend -m \"Add an author\/email comment\"<\/pre>\n<h4 id=\"b02f\" class=\"graf graf--h4 graf-after--pre\">View history<\/h4>\n<pre id=\"cf38\" class=\"graf graf--pre graf-after--h4\">git hist<\/pre>\n<h3 id=\"b8d3\" class=\"graf graf--h3 graf-after--pre\">Moving files<\/h3>\n<p id=\"1165\" class=\"graf graf--p graf-after--h3\">Now we will create the structure of our repository. Let us move the page in the lib directory<\/p>\n<h4 id=\"b786\" class=\"graf graf--h4 graf-after--p\">RUN:<\/h4>\n<pre id=\"73fe\" class=\"graf graf--pre graf-after--h4\">mkdir lib\r\ngit mv hello.html lib\r\ngit status<\/pre>\n<p id=\"db16\" class=\"graf graf--p graf-after--pre\">Moving files with git, we notify git about two things<\/p>\n<ol class=\"postList\">\n<li id=\"df72\" class=\"graf graf--li graf-after--p\">The hello.html file was deleted.<\/li>\n<li id=\"eb6b\" class=\"graf graf--li graf-after--li\">The lib\/hello.html file was created.<\/li>\n<\/ol>\n<p id=\"7219\" class=\"graf graf--p graf-after--li\">Both facts are staged immediately and ready for a commit. Git status command reports the file has been moved.<\/p>\n<h3 id=\"78cc\" class=\"graf graf--h3 graf-after--p\">One more way to move\u00a0files<\/h3>\n<p id=\"f4ee\" class=\"graf graf--p graf-after--h3\">A positive fact about git is that you don\u2019t need to remember about version control to the moment when you need to commit code. What could happen if we were using the operating system command line instead of the git command to move files?<\/p>\n<p id=\"4324\" class=\"graf graf--p graf-after--p\">The following set of commands turned out to be identical to our last actions. It requires more work with same result.<\/p>\n<p id=\"3803\" class=\"graf graf--p graf-after--p\">We can do:<\/p>\n<pre id=\"f390\" class=\"graf graf--pre graf-after--p\">mkdir lib\r\nmv hello.txt lib\r\ngit add lib\/hello.txt\r\ngit rm hello.txt<\/pre>\n<h3 id=\"e187\" class=\"graf graf--h3 graf-after--pre\">Commit new directory<\/h3>\n<p id=\"d2d9\" class=\"graf graf--p graf-after--h3\">Let us commit this movement.<\/p>\n<h4 id=\"79c5\" class=\"graf graf--h4 graf-after--p\">RUN:<\/h4>\n<pre id=\"d78e\" class=\"graf graf--pre graf-after--h4\">git commit -m \"Moved hello.html to lib\"<\/pre>\n<h3 id=\"44ad\" class=\"graf graf--h3 graf-after--pre\">Creating a\u00a0Branch<\/h3>\n<h3 id=\"bce6\" class=\"graf graf--h3 graf-after--h3\">Goals<\/h3>\n<ul class=\"postList\">\n<li id=\"e110\" class=\"graf graf--li graf-after--h3\">To learn how to create a local branch in the repository<\/li>\n<\/ul>\n<p id=\"5f10\" class=\"graf graf--p graf-after--li\">It is time to make our hello world more expressive. Since it may take some time, it is best to move these changes into a new branch to isolate them from master branch changes.<\/p>\n<h3 id=\"fe3e\" class=\"graf graf--h3 graf-after--p\">Create a\u00a0branch<\/h3>\n<p id=\"9a21\" class=\"graf graf--p graf-after--h3\">Let us name our new branch \u00abtestbranch\u00bb.<\/p>\n<h4 id=\"1337\" class=\"graf graf--h4 graf-after--p\">RUN:<\/h4>\n<pre id=\"3e04\" class=\"graf graf--pre graf-after--h4\">git checkout -b testbranch\r\ngit status<\/pre>\n<p id=\"4fc4\" class=\"graf graf--p graf-after--pre\"><strong class=\"markup--strong markup--p-strong\">Note:\u00a0<\/strong>git checkout -b &lt;branch name&gt; is the shortcuts for git branch &lt;branch name&gt; followed by agit checkout &lt;branch name&gt;.<\/p>\n<p id=\"3815\" class=\"graf graf--p graf-after--p\">Note that the git status command reports that you are in the testbranch branch.Make some changes and stage the changes.<\/p>\n<h3 id=\"0e41\" class=\"graf graf--h3 graf-after--p\">Navigating Branches<\/h3>\n<p id=\"086e\" class=\"graf graf--p graf-after--h3\">Now your project has two branches:<\/p>\n<h4 id=\"69ac\" class=\"graf graf--h4 graf-after--p\">RUN:<\/h4>\n<pre id=\"c8f3\" class=\"graf graf--pre graf-after--h4\">git hist --all<\/pre>\n<h3 id=\"41fe\" class=\"graf graf--h3 graf-after--pre\">Switching to the Master\u00a0branch<\/h3>\n<p id=\"517a\" class=\"graf graf--p graf-after--h3\">To switch between branches simply use the git checkout command.<\/p>\n<h4 id=\"dfa3\" class=\"graf graf--h4 graf-after--p\">RUN:<\/h4>\n<pre id=\"b386\" class=\"graf graf--pre graf-after--h4\">git checkout master\r\ncat lib\/hello.txt<\/pre>\n<h3 id=\"2d71\" class=\"graf graf--h3 graf-after--pre\">Changes to master\u00a0branch<\/h3>\n<p id=\"20cc\" class=\"graf graf--p graf-after--h3\">To learn how to work with several branches with different (sometimes conflicting) changes.<\/p>\n<p id=\"1534\" class=\"graf graf--p graf-after--p\">At the time you are changing the style branch, someone decided to change the master branch. He added a README file.<\/p>\n<h3 id=\"d857\" class=\"graf graf--h3 graf-after--p\">Commit changes of README file in the master\u00a0branch.<\/h3>\n<h4 id=\"6b40\" class=\"graf graf--h4 graf-after--h3\">RUN:<\/h4>\n<pre id=\"69a3\" class=\"graf graf--pre graf-after--h4\">git checkout master\r\ngit add README\r\ngit commit -m \"Added README\"<\/pre>\n<h3 id=\"3710\" class=\"graf graf--h3 graf-after--pre\">View the different branches<\/h3>\n<p id=\"1fa9\" class=\"graf graf--p graf-after--h3\">Now we have a repository with two different branches. To view branches and their differences use log command as follows.<\/p>\n<h4 id=\"fd0b\" class=\"graf graf--h4 graf-after--p\">RUN:<\/h4>\n<pre id=\"03c0\" class=\"graf graf--pre graf-after--h4\">git hist --all<\/pre>\n<p id=\"325c\" class=\"graf graf--p graf-after--pre\">We have opportunity to see?\u2014?graph of git hist in action. Adding the?\u2014?graph option to git log causes the construction of a commit tree with the help of simple ASCII characters. We see both branches (style and master) and that the current branch is master HEAD. The Added index.html branch goes prior to both branches.<\/p>\n<p id=\"f65d\" class=\"graf graf--p graf-after--p\">The?\u2014?all flag guarantees that we see all the branches. By default, only the current branch is displayed.<\/p>\n<h3 id=\"fa94\" class=\"graf graf--h3 graf-after--p\">Merging to a single\u00a0branch<\/h3>\n<p id=\"9e22\" class=\"graf graf--p graf-after--h3\">Merging brings changes from two branches into one. Let us go back to the testbranch branch and merge it with master.<\/p>\n<h4 id=\"1795\" class=\"graf graf--h4 graf-after--p\">RUN:<\/h4>\n<pre id=\"115f\" class=\"graf graf--pre graf-after--h4\">git checkout style\r\ngit merge master\r\ngit hist --all<\/pre>\n<h3 id=\"8934\" class=\"graf graf--h3 graf-after--pre\">Creating and Resolving conflict<\/h3>\n<h3 id=\"f392\" class=\"graf graf--h3 graf-after--h3\">Return to the master and create\u00a0conflict<\/h3>\n<p id=\"5965\" class=\"graf graf--p graf-after--h3\">Return to the master branch and make some changes:<\/p>\n<pre id=\"665b\" class=\"graf graf--pre graf-after--p\">git checkout master\r\nvi lib\/hello.txt\r\nTest Status\r\n<strong class=\"markup--strong markup--pre-strong\">Creating conflict<\/strong><\/pre>\n<pre id=\"e6db\" class=\"graf graf--pre graf-after--pre\">git add lib\/hello.html\r\ngit commit -m 'Life is great!'<\/pre>\n<p id=\"446d\" class=\"graf graf--p graf-after--pre\">(<strong class=\"markup--strong markup--p-strong\">Warning:<\/strong>\u00a0make sure you&#8217;ve used single-quotes to avoid problems with bash and\u00a0! character)<\/p>\n<h3 id=\"cace\" class=\"graf graf--h3 graf-after--p\">View branches<\/h3>\n<pre id=\"1522\" class=\"graf graf--pre graf-after--h3\">git hist --all<\/pre>\n<h3 id=\"d136\" class=\"graf graf--h3 graf-after--pre\">Merge the master branch with testbranch<\/h3>\n<p id=\"2dd5\" class=\"graf graf--p graf-after--h3\">Let us go back to the testbranch branch and merge it with a new master branch.<\/p>\n<pre id=\"8333\" class=\"graf graf--pre graf-after--p\">git checkout testbranch\r\ngit merge master<\/pre>\n<p id=\"541c\" class=\"graf graf--p graf-after--pre\">If you open the lib\/hello.html you will see conflict errors<\/p>\n<h3 id=\"f762\" class=\"graf graf--h3 graf-after--p\">Resolution of the\u00a0conflict<\/h3>\n<p id=\"db40\" class=\"graf graf--p graf-after--h3\">You need to resolve the conflict manually. Make changes to lib\/hello.html to achieve the following result.<\/p>\n<p id=\"9905\" class=\"graf graf--p graf-after--p\">Now that you\u2019ve got a good handle on Git, let\u2019s look at GitHub. I\u2019m keen not to overwhelm you, so I\u2019ve made an annotated screenshot of a GitHub project, so that you can quickly become familiar with the most common features. Yes, GitHub is more than simply a project repository, but that\u2019s where you\u2019re likely going to spend most of your time on the site.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Git Fundamentals <\/p>\n<p>&nbsp;<\/p>\n<p id=\"563d\" class=\"graf graf--p graf-after--h4\">Topics To be Covered<\/p>\n<p> Installation <\/p>\n<p id=\"56cd\" class=\"graf graf--p graf-after--li\">2. Setup<\/p>\n<p id=\"d4bd\" class=\"graf graf--p graf-after--p\">3. Creating a Project<\/p>\n<p id=\"0efb\" class=\"graf graf--p graf-after--p\">4. Checking the status of the repository<\/p>\n<p id=\"0e21\" class=\"graf graf--p graf-after--p\">5. Making changes<\/p>\n<p id=\"f546\" class=\"graf graf--p graf-after--p\">6. Staging the changes<\/p>\n<p id=\"e021\" class=\"graf [...] \n\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[96],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7649"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7649"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7649\/revisions"}],"predecessor-version":[{"id":7650,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7649\/revisions\/7650"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7649"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7649"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7649"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}