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

Introduction to Git

Ian Lee
July 25, 2016

Introduction to Git

Collaboration and coordination are at the heart of any multi person software project. Code needs to be shared between developers, shared with users, and inspected by the community. This is particularly prominent in the Open Source community where sharing of highly available and visible code has enabled the creation of such large and diverse software development communities as Python, Bootstrap, and the Linux kernel.

Git is a distributed version control system which has emerged as the industry standard for software development over the past 10 years. This replaces centralized servers as the one source of truth for a code base, and instead gives all developers the same access to the history of a project on their own workstations as the core development team. With the power that Git provides, however, comes a certain level of complexity that can be intimidating to newer users. This talk will focus on the small handful of commands that will allow you to get years of development experience and interact with the broader software community, both here at LLNL and beyond.

Ian Lee

July 25, 2016
Tweet

More Decks by Ian Lee

Other Decks in Technology

Transcript

  1. LLNL-PRES-698283
    This work was performed under the auspices of the U.S. Department of Energy by Lawrence Livermore National Laboratory
    under contract DE-AC52-07NA27344. Lawrence Livermore National Security, LLC
    Introduc)on to Git
    Ian Lee
    [email protected]
    July 25, 2016

    View full-size slide

  2. LLNL-PRES-698283
    2
    §  git --version
    —  2.9.2
    §  Opera7ng System
    —  OS X / Linux
    §  Markdown / Unix Inspired Style FormaEng
    —  $ shell prompt command
    —  `code`
    — 
    —  [OPTIONAL PARAMETER]
    —  `$ foo [bar] `
    Define your terms

    View full-size slide

  3. LLNL-PRES-698283
    3
    What is version control?
    http://smutch.github.io/VersionControlTutorial/

    View full-size slide

  4. LLNL-PRES-698283
    4
    Common Version Control Tools

    View full-size slide

  5. LLNL-PRES-698283
    5
    Fear of Git
    If that doesn't fix it, git.txt contains the
    phone number of a friend of mine who
    understands git. Just wait through a few
    minutes of 'It's really pre=y simple, just
    think of branches as...' and eventually
    you'll learn the commands that will fix
    everything.
    h_ps://xkcd.com/1597/

    View full-size slide

  6. LLNL-PRES-698283
    6
    §  Required
    —  $ git config --global user.name “Ian Lee”
    —  $ git config --global user.email “[email protected]
    §  Op7onal (but recommended)
    —  $ git config --global color.ui true
    —  $ git config --global creden7al.helper “cache --7meout=43200”
    —  $ git config --global push.default simple
    §  For this course
    —  $ git config --global core.pager cat
    §  More informa7on
    —  h_ps://myconfluence.llnl.gov/display/GIT/Git+Config
    Configuring Git: `man git-config`

    View full-size slide

  7. LLNL-PRES-698283
    7
    Crea)ng a new repo: `git init`

    View full-size slide

  8. LLNL-PRES-698283
    8
    Seeing what’s changed: `git status`

    View full-size slide

  9. LLNL-PRES-698283
    9
    Tracking a new file: `git add `

    View full-size slide

  10. LLNL-PRES-698283
    10
    Ini)al commit: `git commit -m “” `

    View full-size slide

  11. LLNL-PRES-698283
    11
    Making changes: `git diff [] [--] [<filename>]`

    View full-size slide

  12. LLNL-PRES-698283
    12
    Making changes: `git diff [] [--] [<filename>]`

    View full-size slide

  13. LLNL-PRES-698283
    13
    CommiSng All Changes: `git commit -a -m””`

    View full-size slide

  14. LLNL-PRES-698283
    14
    Staged vs not staged vs untracked

    View full-size slide

  15. LLNL-PRES-698283
    15
    Good Commit Messages
    Merge branch 'asdfasjkfdlas/alkdjf' into
    sdkjfls-final
    h_ps://xkcd.com/1296/

    View full-size slide

  16. LLNL-PRES-698283
    16
    Visualizing Changes: `git show [reference]`

    View full-size slide

  17. LLNL-PRES-698283
    17
    Visualizing Changes: `git show [reference]`

    View full-size slide

  18. LLNL-PRES-698283
    18
    Visualizing Changes: `git log`

    View full-size slide

  19. LLNL-PRES-698283
    19
    Visualizing Changes: `git log --stat`

    View full-size slide

  20. LLNL-PRES-698283
    20
    Visualizing Changes: `git log` - advanced

    View full-size slide

  21. LLNL-PRES-698283
    21
    Visualizing Changes: `)g`

    View full-size slide

  22. LLNL-PRES-698283
    22
    Visualizing Changes: `gitk [--all]`

    View full-size slide

  23. LLNL-PRES-698283
    23
    Making Mistakes

    View full-size slide

  24. LLNL-PRES-698283
    24
    Making Mistakes

    View full-size slide

  25. LLNL-PRES-698283
    25
    Discarding Changes: `git checkout [reference] -- `

    View full-size slide

  26. LLNL-PRES-698283
    26
    Doing some work

    View full-size slide

  27. LLNL-PRES-698283
    27
    Doing some work

    View full-size slide

  28. LLNL-PRES-698283
    28
    Star)ng to branch out: `git checkout -b `

    View full-size slide

  29. LLNL-PRES-698283
    29
    Star)ng to branch out: `git checkout -b `

    View full-size slide

  30. LLNL-PRES-698283
    30
    Star)ng to branch out: `git checkout -b `

    View full-size slide

  31. LLNL-PRES-698283
    31
    Branches (and tags) are like s)cky notes

    View full-size slide

  32. LLNL-PRES-698283
    32
    Branches: `git branch`

    View full-size slide

  33. LLNL-PRES-698283
    33
    Renaming a branch: `git branch -m `

    View full-size slide

  34. LLNL-PRES-698283
    34
    Crea)ng new branches: `git branch `

    View full-size slide

  35. LLNL-PRES-698283
    35
    Crea)ng new branches: `git branch `

    View full-size slide

  36. LLNL-PRES-698283
    36
    Switching branches: `git checkout `

    View full-size slide

  37. LLNL-PRES-698283
    37
    Tangent: The “HEAD” branch

    View full-size slide

  38. LLNL-PRES-698283
    38
    Dele)ng branches: `git branch -d `

    View full-size slide

  39. LLNL-PRES-698283
    39
    REALLY dele)ng branches: `git branch -D `

    View full-size slide

  40. LLNL-PRES-698283
    40
    Working on Master

    View full-size slide

  41. LLNL-PRES-698283
    41
    Divergence when working on mul)ple branches

    View full-size slide

  42. LLNL-PRES-698283
    42
    Merging branches: `git merge `

    View full-size slide

  43. LLNL-PRES-698283
    43
    Undo: `git reset --hard `

    View full-size slide

  44. LLNL-PRES-698283
    44
    Undo: `git reset `

    View full-size slide

  45. LLNL-PRES-698283
    45
    Undo: `git reset `

    View full-size slide

  46. LLNL-PRES-698283
    46
    Current State: We’ll come back to this...

    View full-size slide

  47. LLNL-PRES-698283
    47
    Working with remotes

    View full-size slide

  48. LLNL-PRES-698283
    48
    Finding something to contribute to: Atlassian BitBucket

    View full-size slide

  49. LLNL-PRES-698283
    49
    Finding something to contribute to: GitHub

    View full-size slide

  50. LLNL-PRES-698283
    50
    Star)ng from exis)ng: `git clone `

    View full-size slide

  51. LLNL-PRES-698283
    51
    Lis)ng the remotes: `git remote -v`

    View full-size slide

  52. LLNL-PRES-698283
    52
    master vs origin/master

    View full-size slide

  53. LLNL-PRES-698283
    53
    Adding a remote: `git remote add `

    View full-size slide

  54. LLNL-PRES-698283
    54
    Where is origin-ssh?

    View full-size slide

  55. LLNL-PRES-698283
    55
    Fetching remotes: `git fetch `

    View full-size slide

  56. LLNL-PRES-698283
    56
    master vs origin/master vs origin-ssh/master

    View full-size slide

  57. LLNL-PRES-698283
    57
    ForgeSng a remote: `git remote rm `

    View full-size slide

  58. LLNL-PRES-698283
    58
    Crea)ng something new: `git checkout -b `

    View full-size slide

  59. LLNL-PRES-698283
    59
    Crea)ng something new: `git checkout -b `

    View full-size slide

  60. LLNL-PRES-698283
    60
    Contribu)ng back: `git push --set-upstream `

    View full-size slide

  61. LLNL-PRES-698283
    61
    Contribu)ng back: `git push --set-upstream `

    View full-size slide

  62. LLNL-PRES-698283
    62
    Merging to remote branches

    View full-size slide

  63. LLNL-PRES-698283
    63
    Pushing to master: `git push [ ]`

    View full-size slide

  64. LLNL-PRES-698283
    64
    Trimming branches: `git push --delete `

    View full-size slide

  65. LLNL-PRES-698283
    65
    Trimming branches: `git push --delete `

    View full-size slide

  66. LLNL-PRES-698283
    66
    Git Flow
    https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow

    View full-size slide

  67. LLNL-PRES-698283
    67
    Git Flow: Main Branches
    https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow

    View full-size slide

  68. LLNL-PRES-698283
    68
    Git Flow: Feature Branches
    https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow

    View full-size slide

  69. LLNL-PRES-698283
    69
    Git Flow: Release Branches
    https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow

    View full-size slide

  70. LLNL-PRES-698283
    70
    Git Flow: Maintenance Branches
    https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow

    View full-size slide

  71. LLNL-PRES-698283
    71
    §  Git Confluence Space
    —  h_ps://myconfluence.llnl.gov/display/git
    §  Git Tutorials
    —  h_ps://try.github.io/
    —  h_p://learngitbranching.js.org/
    —  h_ps://www.atlassian.com/git/
    §  Commandline help
    —  $ man git
    —  $ git –help
    §  This talk
    —  h_ps://speakerdeck.com/ianlee1521/introduc7on-to-git
    GeSng Help

    View full-size slide

  72. Questions?
    $ cat git.txt
    Ian Lee – [email protected]

    View full-size slide