Using Git: An Overview

Hashem Nasarat

February 15, 2013

What is git?

Using Git

Git: Local Repository Only

Basic Usage (local repository)

    repo   files
     ___
    [   ]   *
    [___]
     ___
    [ * ]
    [___]
     __________________
    [ * (HEAD) message ]
    [__________________]

Basic Usage (local repository)

     ___________________
    [ * (HEAD) message3 ]
    [ * message2        ]
    [ * message         ]
    [___________________]

Other Useful Basic Commands

Git: Local and Remote Repositories

GitHub Basics

Basic Usage (local + remote repository)

Remote: Initial State

     local           remote
    (laptop)        (GitHub)
     ____            ____
    [ *  ]          [    ]
    [ *  ]          [    ]
    [ *  ]          [    ]
    [____]          [____]

Remote: Updating the remote

     local           remote
    (laptop)        (GitHub)
     ____    push    ____
    [ *  ]  ----->  [ *  ]
    [ *  ]          [ *  ]
    [ *  ]          [ *  ]
    [____]          [____]

Remote: Creating a new local

     local           remote         local
     (laptop)       (GitHub)        (halligan)
     ____            ____    clone    ____
    [ *  ]          [ *  ]  ------>  [ *  ]
    [ *  ]          [ *  ]           [ *  ]
    [ *  ]          [ *  ]           [ *  ]
    [____]          [____]           [____]

Remote: Updating the local

     local           remote         local
     (laptop)       (GitHub)        (halligan)
     ____            ____             ____
    [ *  ]  (push)  [ *  ]   pull    [ *  ]
    [ *  ]  ----->  [ *  ]  ------>  [ *  ]
    [ *  ]          [ *  ]           [ *  ]
    [ *  ]          [ *  ]           [ *  ]
    [____]          [____]           [____]

Viewing a Repository 1

Viewing a Repository 2

Committing and Good Commit Style

Adding and Committing

Commit Style

Add alt attribute to every img

As per Section 508 Amendment to the Rehabilitation Act of 1973
and the HTML 5 specification, every img should have an alt
attribute which "provides equivalent content for those who
cannot process images or who have image loading disabled".

Undoing Commits and Fixing Things

Git reset

Git reset example

    * 31a3f57 (HEAD, master) Third commit
    * 20ea82d Second commit
    * 9ef5cfb First commit

Git reset example

    * 20ea82d (HEAD, master) Second commit
    * 9ef5cfb First commit

Un-undoing Commits

    20ea82d HEAD@{0}: reset: moving to HEAD~1
    31a3f57 HEAD@{1}: checkout: moving from 20ea82d to master
    20ea82d HEAD@{2}: checkout: moving from master to HEAD~1
    31a3f57 HEAD@{3}: commit: Third commit
    20ea82d HEAD@{4}: commit: Second commit
    9ef5cfb HEAD@{5}: commit (initial): First commit

Un-undoing Commits

    * 31a3f57 (HEAD, master) Third commit
    * 20ea82d Second commit
    * 9ef5cfb First commit

Working with Branches

Branches

      * 7a0fc15 Patch.hs: Fix incorrect editsToChangeHunks offsets
      * e564f63 Make the type of Edit more general.
    * | 0bbe999 Implements applyPatch
    * | b6d7003 Implements sequencePatches
    |/
    * 6f2a864 Paralell patch changes

Using Branches

Combining Branches

  1. git merge <branch to merge in>
    • Produces a commit with multiple parents
    *   ca5ac46 Merge branch 'master' of github.com:jmont/nor
    |\
    | * 7a0fc15 Patch.hs: Fix incorrect editsToChangeHunks offsets
    | * e564f63 Make the type of Edit more general.
    * | 0bbe999 Implements applyPatch
    * | b6d7003 Implements sequencePatches
    |/
    * 6f2a864 Paralell patch changes
  1. git rebase <branch to rebase onto>
    • Removes the branch by making the branch’s commits stem from the end of the other.
    * 7a0fc15 Patch.hs: Fix incorrect editsToChangeHunks offsets
    * e564f63 Make the type of Edit more general.
    * 0bbe999 Implements applyPatch
    * b6d7003 Implements sequencePatches
    * 6f2a864 Paralell patch changes

Conflicts

    these lines
    are not
    in conflict
    <<<<<<
    THESE ARE IN CONFLICT!
    ======
    These are in conflict.
    >>>>>> version 2
    these lines
    are good too

GitHub Forking and Pull Requests

GitHub: Forking

     remote          remote
     tuftsdev/       hnasar/
     running-dogs    running-dogs
     ____            ____
    [ *  ]   fork   [ *  ]
    [ *  ]  ----->  [ *  ]
    [ *  ]          [ *  ]
    [____]          [____]

GitHub: Pull Request

     remote          remote
     tuftsdev/       hnasar/
     running-dogs    running-dogs
     ____           ____
    [_*__] <------ [ *  ]
    [ *  ]   pull  [ *  ]
    [ *  ] request [ *  ]
    [ *  ]         [ *  ]
    [____]         [____]

GitHub: No passwords

Time Travel

Checkout & Blame

Commit-ishs

Rewriting History

End

Questions/Comments

Quiz

  1. Create a repository
  2. Commit thrice
  3. Create a branch from the first commit and add another commit or two.
  4. Merge the new branch into master
  5. Undo the merge in master
  6. Rebase the new branch onto master instead
  7. Squash all the commits on top of the initial commit

This work is licensed under the Creative Commons Attribution 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/.