Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Git and GitHub: an introduction

Wendy Liu
August 07, 2013

Git and GitHub: an introduction

Internal presentation to the Network Dynamics group on using Git and GitHub.

Wendy Liu

August 07, 2013
Tweet

More Decks by Wendy Liu

Other Decks in Programming

Transcript

  1. 1 / 41
    an introduction
    and :

    View Slide

  2. 2 / 41
    Distributed.
    SVN

    View Slide

  3. 3 / 41
    Distributed.
    Git

    View Slide

  4. 4 / 41
    Fast.
    Committing and pushing code: 2164+, 2259-
    git: 0.64 s
    SVN: 2.60 s
    Committing and pushing 1000, 1k images
    git: 1.53 s
    SVN: 24.70 s
    Viewing the log of the last 50 commits
    git: 0.01 s
    SVN: 0.38 s

    View Slide

  5. 5 / 41
    Staging area.
    Index
    Repository
    git add
    git commit

    View Slide

  6. 6 / 41
    Let's start a repository.

    View Slide

  7. 7 / 41
    $ git clone
    $ git clone https://github.com/networkdynamics/zenlib zen

    View Slide

  8. 8 / 41
    $ git init
    $ git init
    $ git remote add origin https://github.com/networkdynamics/zenlib

    View Slide

  9. 9 / 41
    $ git status
    # On branch master
    #
    # Initial commit
    #
    nothing to commit (create/copy files and use "git add" to track)

    View Slide

  10. 10 / 41
    $ git add
    $ echo "Under construction" > README
    $ git add readme

    View Slide

  11. 11 / 41
    $ git status
    # On branch master
    #
    # Initial commit
    #
    # Changes to be committed:
    # (use "git rm --cached ..." to unstage)
    #
    # new file: README
    #

    View Slide

  12. 12 / 41
    $ git diff
    $ git diff
    $ echo "Coming soon" > README
    $ cat README
    Coming soon
    Staging area (index) vs working tree (filesystem)

    View Slide

  13. 13 / 41
    $ git diff
    diff --git a/README b/README
    index 03b5361..3c0b0b0 100644
    --- a/README
    +++ b/README
    @@ -1 +1 @@
    -Under construction
    +Coming soon

    View Slide

  14. 14 / 41
    $ git commit
    $ git commit -m "Add under construction message"
    [master (root-commit) c841ccc] Add under construction message
    1 file changed, 1 insertion(+)
    create mode 100644 README
    Filesystem -> Staging area only

    View Slide

  15. 15 / 41
    $ git show
    Shows the last commit (or any commit, or a tag, etc)

    View Slide

  16. 16 / 41
    $ git show
    commit c841cccbdfdc3dbc9e5333695e492a0a2fafdfa0
    Author: dellsystem
    Date: Tue Aug 7 13:41:03 2012 -0400
    Add under construction message
    diff --git a/README b/README
    new file mode 100644
    index 0000000..03b5361
    --- /dev/null
    +++ b/README
    @@ -0,0 +1 @@
    +Under construction

    View Slide

  17. 17 / 41
    $ git checkout
    Discard changes in working directory
    $ cat README
    Coming soon
    $ git checkout README
    $ cat README
    Under construction

    View Slide

  18. 18 / 41
    $ git commit --amend
    Change the last commit
    $ echo "Under construction!" > README
    $ cat README
    Under construction!
    $ git add README
    $ git commit --amend

    View Slide

  19. 19 / 41
    $ echo "Under construction!" > README
    $ cat README
    Under construction!
    $ git add README
    $ git commit --amend

    View Slide

  20. 20 / 41
    1 Add "Under construction!" message
    2
    3 # Please enter the commit message for your changes. Lines starting
    4 # with '#' will be ignored, and an empty message aborts the commit.
    5 # On branch master
    6 #
    7 # Initial commit
    8 #
    9 # Changes to be committed:
    10 # (use "git rm --cached ..." to unstage)
    11 #
    12 # new file: README
    13 #

    View Slide

  21. 21 / 41
    $ git log
    Show the log of all commit activity
    $ git log
    commit 76942d9c793578979e9cd6465f15b13e41d13d29
    Author: dellsystem
    Date: Tue Aug 7 13:41:03 2012 -0400
    Add "Under construction!" message

    View Slide

  22. 22 / 41
    $ git reset
    $ echo "Will be ready September 1." >> README
    $ cat README
    Under construction!
    Will be ready September 1.
    $ git add .
    $ git status
    # On branch master
    # Changes to be committed:
    # (use "git reset HEAD ..." to unstage)
    #
    # modified: README
    #

    View Slide

  23. 23 / 41
    $ git reset HEAD README
    Unstaged changes after reset:
    M README
    $ git status
    # On branch master
    # Changes not staged for commit:
    # (use "git add ..." to update what will be committed)
    # (use "git checkout -- ..." to discard changes in working directory)
    #
    # modified: README
    #
    no changes added to commit (use "git add" and/or "git commit -a")

    View Slide

  24. 24 / 41
    $ git add --patch
    Selectively committing changes in a file

    View Slide

  25. 25 / 41
    def extract_feature(self, user):
    user_name = self.get_data(user)
    # Make it upper case and take everything before the first space
    first_name = user_name.upper().split()[0]
    value = self.data.get(first_name, 0.0)
    log.debug("%s: %.3f" % (first_name, value))
    - return [vlaue]
    + return [value]
    ...
    +#================================
    +# Actual features below
    +#================================
    class NaiveWords(NaiveFeature):
    feature = 'words'
    class NaiveDigrams(NaiveFeature):
    } want
    } do not want

    View Slide

  26. 26 / 41
    $ git add --patch features.py
    [...]
    - return [vlaue]
    + return [value]
    Stage this hunk [y,n,q,a,d,/,K,j,J,g,e,?]? y
    [...]
    +#================================
    +# Actual features below
    +#================================
    Stage this hunk [y,n,q,a,d,/,K,j,J,g,e,?]? q
    -> yes, stage this hunk
    -> no, and quit

    View Slide

  27. 27 / 41
    $ git branch
    master (stable)
    bugfix
    awesomenewfeature

    View Slide

  28. 28 / 41
    $ git branch
    Or, any other workflow.
    master
    develop
    master somebranch anotherbranch etc

    View Slide

  29. 29 / 41
    $ git push
    Pushing your changes to a server
    $ git push origin master -u

    View Slide

  30. 30 / 41
    $ git push origin master -u
    # On branch master
    # Your branch is ahead of 'origin/master' by 1 commit.
    Branch tracking

    View Slide

  31. 31 / 41
    $ git pull
    Keeping your local copy up-to-date
    $ git pull

    View Slide

  32. 32 / 41
    Merge conflicts

    View Slide

  33. 33 / 41
    Rebasing
    Rewording commit messages
    Reordering commits
    Combining commits
    and more!

    View Slide

  34. 34 / 41
    Rebasing
    $ git rebase -i HEAD~5 The last 5 commits

    View Slide

  35. 35 / 41
    Aliasing
    $ git s -> status
    $ git d -> diff
    $ git p -> add --patch

    View Slide

  36. 36 / 41
    Multiple remote branches

    View Slide

  37. 37 / 41
    Whitespace problems
    this line has trailing whitespace

    View Slide

  38. 38 / 41
    Tagging
    $ git tag v1.0.0 -m "First gold release"

    View Slide

  39. 39 / 41
    Bisecting

    View Slide

  40. 40 / 41
    Git resources
    https://help.github.com/
    Pro Git (http://git-scm.com/book)
    Git man pages (git help, git add help)

    View Slide

  41. 41 / 41
    Github
    issues :: pull requests :: comparison view :: commit view :: blame :: history :: wiki :: markdown

    View Slide