Introduction to Git

C416a04a16b233e65afd993815c167dd?s=47 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.

C416a04a16b233e65afd993815c167dd?s=128

Ian Lee

July 25, 2016
Tweet

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 ian@llnl.gov July 25, 2016
  2. LLNL-PRES-698283 2 §  git --version —  2.9.2 §  Opera7ng System

    —  OS X / Linux §  Markdown / Unix Inspired Style FormaEng —  $ shell prompt command —  `code` —  <REQUIRED, BUT CUSTOM PARAMETER> —  [OPTIONAL PARAMETER] —  `$ foo [bar] <baz>` Define your terms
  3. LLNL-PRES-698283 3 What is version control? http://smutch.github.io/VersionControlTutorial/

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

  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/
  6. LLNL-PRES-698283 6 §  Required —  $ git config --global user.name

    “Ian Lee” —  $ git config --global user.email “lee1001@llnl.gov” §  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`
  7. LLNL-PRES-698283 7 Crea)ng a new repo: `git init`

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

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

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

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

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

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

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

  15. LLNL-PRES-698283 15 Good Commit Messages Merge branch 'asdfasjkfdlas/alkdjf' into sdkjfls-final

    h_ps://xkcd.com/1296/
  16. LLNL-PRES-698283 16 Visualizing Changes: `git show [reference]`

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

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

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

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

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

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

  23. LLNL-PRES-698283 23 Making Mistakes

  24. LLNL-PRES-698283 24 Making Mistakes

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

  26. LLNL-PRES-698283 26 Doing some work

  27. LLNL-PRES-698283 27 Doing some work

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

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

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

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

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

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

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

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

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

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

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

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

  40. LLNL-PRES-698283 40 Working on Master

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

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

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

  44. LLNL-PRES-698283 44 Undo: `git reset <reference>`

  45. LLNL-PRES-698283 45 Undo: `git reset <reference>`

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

  47. LLNL-PRES-698283 47 Working with remotes

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

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

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

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

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

  53. LLNL-PRES-698283 53 Adding a remote: `git remote add <alias> <url>`

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

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

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

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

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

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

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

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

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

  63. LLNL-PRES-698283 63 Pushing to master: `git push [<remote> <branch>]`

  64. LLNL-PRES-698283 64 Trimming branches: `git push --delete <remote> <branch>`

  65. LLNL-PRES-698283 65 Trimming branches: `git push --delete <remote> <branch>`

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

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

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

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

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

  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
  72. Questions? $ cat git.txt Ian Lee – ian@llnl.gov