A brief introduction to git and Github

2df7339e6f646abdc75d6fe1e954814a?s=47 Kiko
March 31, 2016

A brief introduction to git and Github

This presentation covers an introduction to distributed version control systems, moves on to explain the basics of git: how to track files, perform commits and fix merge conflicts. Finally, it provides links to different distributed workflows and focuses on the Central repository workflow. All of this is explained to work at the command line level but links to graphical interfaces are provided at the end of the presentation, together with some other useful resources.

2df7339e6f646abdc75d6fe1e954814a?s=128

Kiko

March 31, 2016
Tweet

Transcript

  1. A brief introduction to git and Github Kiko Fernandez-Reyes 1

  2. Distributed Version Control System • Remote and local copies •

    Keep track of file changes • Knows what you did last summer • Remembers authorship Git: 2
  3. Distributed Version Control System • Remote and local copies •

    Keep track of file changes • Knows what you did last summer • Remembers authorship Git: 2
  4. Distributed Version Control System • Remote and local copies •

    Keep track of file changes • Knows what you did last summer • Remembers authorship Git: 2
  5. Distributed Version Control System • Remote and local copies •

    Keep track of file changes • Knows what you did last summer • Remembers authorship Git: 2
  6. Github & Git • Set up an account • Create

    a repository (repo) • Add things to your repo • Branch workflow • Share changes with your team 3
  7. Git Basics

  8. • Create Github account • Set up Git (link Github)

    5 Linux & OS X $ git config --global push.default simple $ git config --global core.editor “subl -n -w” link config editors
  9. • Create Github account • Set up Git (link Github)

    5 Windows $ git config --global push.default simple $ git config --global core.editor “subl -n -w” link config editors
  10. Create a repository (repo) Add collaborators to repo Clone repo

    on local machine $ git clone https://github.com/kikofernandez/git-intro.git $ git clone <address-repo> Remote Remote Local = the remote server, Github = your local machine Local Initial Steps: Remote
  11. Create a repository (repo) Add collaborators to repo Clone repo

    on local machine $ git clone https://github.com/kikofernandez/git-intro.git Remote Remote Local = the remote server, Github = your local machine Local Initial Steps: Remote
  12. Git: Basics 7 Local

  13. Git: Basics 7 Holds actual files Which files form commit

    Commits Local
  14. Git: Basics 8 Working Directory Staging Area Folder of your

    repository, e.g. ~/git-intro Commands: $ git add <file> Changes that make up a commit Commands: $ git commit -m “message” Local
  15. Git: Basics 8 Working Directory Staging Area Folder of your

    repository, e.g. ~/git-intro Commands: $ git add <file> this is an introduction to the course … intro.md Changes that make up a commit Commands: $ git commit -m “message” Local
  16. Git: Basics 8 Working Directory Staging Area Folder of your

    repository, e.g. ~/git-intro Commands: $ git add <file> this is an introduction to the course … intro.md $ git add intro.md Changes that make up a commit Commands: $ git commit -m “message” Local
  17. Git: Basics 8 Working Directory Staging Area Folder of your

    repository, e.g. ~/git-intro Commands: $ git add <file> this is an introduction to the course … intro.md $ git add intro.md Changes that make up a commit Commands: $ git commit -m “message” Local
  18. Git: Basics 8 Working Directory Staging Area Folder of your

    repository, e.g. ~/git-intro Commands: $ git add <file> this is an introduction to the course … intro.md $ git add intro.md Changes that make up a commit Commands: $ git commit -m “message” $ git commit -m “add intro.md file” Local
  19. Git: Basics 8 Working Directory Staging Area Folder of your

    repository, e.g. ~/git-intro Commands: $ git add <file> this is an introduction to the course … intro.md $ git add intro.md Changes that make up a commit Commands: $ git commit -m “message” $ git commit -m “add intro.md file” Local
  20. Git: Basics 8 Working Directory Staging Area Folder of your

    repository, e.g. ~/git-intro Commands: $ git add <file> this is an introduction to the course … intro.md $ git add intro.md Changes that make up a commit Commands: $ git commit -m “message” $ git commit -m “add intro.md file” this is an introduction to the course … intro.md Local
  21. Git: Basics 8 Working Directory Staging Area Folder of your

    repository, e.g. ~/git-intro Commands: $ git add <file> this is an introduction to the course … intro.md $ git add intro.md Changes that make up a commit Commands: $ git commit -m “message” $ git commit -m “add intro.md file” this is an introduction to the course … intro.md Local
  22. Git: Basics 8 Working Directory Staging Area Folder of your

    repository, e.g. ~/git-intro Commands: $ git add <file> this is an introduction to the course … intro.md $ git add intro.md Changes that make up a commit Commands: $ git commit -m “message” $ git commit -m “add intro.md file” this is an introduction to the course … intro.md this is an introduction to the course … intro.md Local
  23. Git: Basics 8 Working Directory Staging Area Folder of your

    repository, e.g. ~/git-intro Commands: $ git add <file> this is an introduction to the course … intro.md $ git add intro.md Changes that make up a commit Commands: $ git commit -m “message” $ git commit -m “add intro.md file” this is an introduction to the course … intro.md this is an introduction to the course … intro.md Local
  24. Git: Basics 8 Working Directory Staging Area Folder of your

    repository, e.g. ~/git-intro Commands: $ git add <file> this is an introduction to the course … intro.md $ git add intro.md Changes that make up a commit Commands: $ git commit -m “message” $ git commit -m “add intro.md file” this is an introduction to the course … intro.md this is an introduction to the course … intro.md Local
  25. Git: Logs 9 $ git log -p How do I

    see the changes? Remote Local
  26. Git: Logs 9 $ git log -p How do I

    see the changes? Remote Local
  27. Git: Logs 9 $ git log -p How do I

    see the changes? Remote Local
  28. Git: Logs 9 $ git log -p How do I

    see the changes? Remote Local
  29. Commit early, commit often A tip for version controlling -

    not for relationships ( ) 10 Best tip you will ever receive:
  30. Git branching (optional) 11

  31. Git: Branching Local 3ddf4 master Branches: they are pointers to

    commits / versions Default branch: master $ git add intro.md; git commit -m “update” 12
  32. Git: Branching Local 3ddf4 master Branches: they are pointers to

    commits / versions Default branch: master $ git add intro.md; git commit -m “update” 12ab56 12
  33. Git: Branching Local 3ddf4 master Branches: they are pointers to

    commits / versions Default branch: master $ git add intro.md; git commit -m “update” 12ab56 3eee8 12
  34. Git: Branching Local 3ddf4 master Branches: they are pointers to

    commits / versions Default branch: master 13
  35. Git: Branching Local 3ddf4 master Branches: they are pointers to

    commits / versions Default branch: master $ git branch frontend frontend 13
  36. Git: Branching Local 3ddf4 HEAD master Branches: they are pointers

    to commits / versions Default branch: master $ git branch frontend frontend HEAD: pointer to the current branch 13
  37. Git: Branching Local 3ddf4 HEAD master Branches: they are pointers

    to commits / versions Default branch: master $ git branch frontend frontend HEAD: pointer to the current branch $ git checkout frontend 13
  38. Git: Branching Local 3ddf4 HEAD Branches: they are pointers to

    commits / versions Default branch: master $ git branch frontend HEAD: pointer to the current branch $ git checkout frontend master frontend 13
  39. Git: Branching Local 3ddf4 HEAD Branches: they are pointers to

    commits / versions Default branch: master $ git branch frontend 12ab56 HEAD: pointer to the current branch $ git checkout frontend master frontend $ git commit -a -m “commit everything” 13
  40. Git: Branching Local 3ddf4 HEAD Branches: they are pointers to

    commits / versions Default branch: master $ git branch frontend 12ab56 3eee8 HEAD: pointer to the current branch $ git checkout frontend master frontend $ git commit -a -m “commit everything” 13
  41. Git: Branching Local 3ddf4 HEAD Branches: they are pointers to

    commits / versions Default branch: master 12ab56 3eee8 HEAD: pointer to the current branch master frontend 14
  42. Git: Branching Local 3ddf4 HEAD Branches: they are pointers to

    commits / versions Default branch: master $ git checkout master 12ab56 3eee8 HEAD: pointer to the current branch master frontend 14
  43. Git: Branching Local 3ddf4 HEAD master Branches: they are pointers

    to commits / versions Default branch: master $ git checkout master frontend 12ab56 3eee8 HEAD: pointer to the current branch 14
  44. Git: Branching Local 3ddf4 HEAD master How to merge master

    with the changes in frontend? $ git merge frontend frontend 12ab56 3eee8 HEAD: pointer to the current branch 15
  45. Git: Branching Local 3ddf4 HEAD master How to merge master

    with the changes in frontend? $ git merge frontend frontend 12ab56 3eee8 HEAD: pointer to the current branch 15
  46. Git Conflicts

  47. + Test test + This is my first line Git:

    Conflicts Local 3ddf4 $ git merge frontend frontend 12ab56 3eee8 17 HEAD master Commits: 12ab56 and 3eee8 add a line in same file
  48. + Test test + This is my first line Git:

    Conflicts Local 3ddf4 $ git merge frontend frontend 12ab56 3eee8 17 6664f HEAD master Commits: 12ab56 and 3eee8 add a line in same file
  49. + Test test + This is my first line Git:

    Conflicts Local 3ddf4 $ git merge frontend frontend 12ab56 3eee8 17 6664f HEAD master Conflicts: 12ab56 and 3eee8 update same line Commits: 12ab56 and 3eee8 add a line in same file
  50. + Test test + This is my first line Git:

    Conflicts Local 3ddf4 $ git merge frontend frontend 12ab56 3eee8 17 6664f HEAD master Conflicts: 12ab56 and 3eee8 update same line Commits: 12ab56 and 3eee8 add a line in same file
  51. + Test test + This is my first line Git:

    Conflicts Local 3ddf4 $ git merge frontend frontend 12ab56 3eee8 17 6664f HEAD master Conflicts: 12ab56 and 3eee8 update same line Commits: 12ab56 and 3eee8 add a line in same file
  52. + Test test + This is my first line Git:

    Conflicts Local 3ddf4 $ git merge frontend frontend 12ab56 3eee8 17 6664f HEAD master Conflicts: 12ab56 and 3eee8 update same line Commits: 12ab56 and 3eee8 add a line in same file
  53. + Test test + This is my first line Git:

    Conflicts Local 3ddf4 $ git merge frontend frontend 12ab56 3eee8 17 6664f HEAD master Conflicts: 12ab56 and 3eee8 update same line Commits: 12ab56 and 3eee8 add a line in same file
  54. Git conflicts: Recipe $ git add <name-of-files-with-conflicts> $ git commit

    When you get conflicts: 1. fix the conflicts 2. 3.
  55. Team work 19

  56. Github ❤ Git • So far, your changes are in

    local computer • Problem: What if you drop the computer? Work in Teams? 20
  57. Github ❤ Git • So far, your changes are in

    local computer • Problem: What if you drop the computer? Work in Teams? • Solution: Github saves your work in the “cloud” 20
  58. Github ❤ Git • Push your local changes to your

    remote repository $ git push origin master Name of the remote url: by default, it’s always called origin Name of your branch: your initial branch is always called master 21 Remote $ git remote -v
  59. Github ❤ Git • Pull remote changes to your local

    repository $ git pull origin master Name of the remote url: by default, it’s always called origin Name of the local branch to pull into: your initial branch is always called master 22 Remote $ git remote -v
  60. 3ddf4 HEAD master The remote end is similar to a

    branch $ git commit -am “commit everything” origin/master HEAD: pointer to the current branch 23 Github ❤ Git Remote
  61. 3ddf4 HEAD master The remote end is similar to a

    branch $ git commit -am “commit everything” origin/master 12ab56 HEAD: pointer to the current branch 23 Github ❤ Git Remote
  62. 3ddf4 HEAD master The remote end is similar to a

    branch $ git commit -am “commit everything” origin/master 12ab56 3eee8 HEAD: pointer to the current branch 23 Github ❤ Git Remote
  63. 3ddf4 HEAD master The remote end is similar to a

    branch $ git commit -am “commit everything” origin/master 12ab56 3eee8 HEAD: pointer to the current branch 23 Github ❤ Git Remote $ git push origin master
  64. 3ddf4 HEAD master The remote end is similar to a

    branch $ git commit -am “commit everything” origin/master 12ab56 3eee8 HEAD: pointer to the current branch 23 Github ❤ Git Remote $ git push origin master
  65. Distributed Recipes • Centralised Workflow • Integration-Manager Workflow • Dictator-Lieutenants

    Workflow *recipes = workflow
  66. Distributed Recipes • Centralised Workflow • Integration-Manager Workflow • Dictator-Lieutenants

    Workflow *recipes = workflow
  67. Centralised recipe $ git pull origin master Easy start: everyone

    works on the same branch $ git add <files> Do some work $ git commit -m “<message>” $ git push origin master rinse and repeat Works until you get conflicts
  68. 3ddf4 HEAD master 26 Conflicts in Centralised recipe @kikofernandez 3ddf4

    origin/master Github 3ddf4 HEAD master origin/master origin/master @kikofernandez @supercooldave @supercooldave
  69. 3ddf4 HEAD master 26 Conflicts in Centralised recipe @kikofernandez 3ddf4

    origin/master Github 3ddf4 HEAD master origin/master origin/master $ git commit -am “stuff” @kikofernandez @supercooldave @supercooldave
  70. 3ddf4 HEAD master 12ab56 26 Conflicts in Centralised recipe @kikofernandez

    3ddf4 origin/master Github 3ddf4 HEAD master origin/master origin/master $ git commit -am “stuff” @kikofernandez @supercooldave @supercooldave
  71. 3ddf4 HEAD master 12ab56 26 Conflicts in Centralised recipe @kikofernandez

    3ddf4 origin/master Github 3ddf4 HEAD master origin/master origin/master $ git commit -am “stuff” $ git commit -am “work” @kikofernandez @supercooldave @supercooldave
  72. 3ddf4 HEAD master 12ab56 26 Conflicts in Centralised recipe @kikofernandez

    3ddf4 origin/master Github 3ddf4 HEAD master 3eba4 origin/master origin/master $ git commit -am “stuff” $ git commit -am “work” @kikofernandez @supercooldave @supercooldave
  73. 3ddf4 HEAD master 12ab56 26 Conflicts in Centralised recipe @kikofernandez

    3ddf4 origin/master Github 3ddf4 HEAD master 3eba4 origin/master origin/master $ git push origin master $ git commit -am “stuff” $ git commit -am “work” @kikofernandez @supercooldave @supercooldave
  74. 3ddf4 HEAD master 12ab56 26 Conflicts in Centralised recipe @kikofernandez

    3ddf4 origin/master Github 3ddf4 HEAD master 3eba4 origin/master origin/master $ git push origin master $ git commit -am “stuff” $ git commit -am “work” 12ab56 @kikofernandez @supercooldave @supercooldave
  75. 3ddf4 HEAD master 12ab56 26 Conflicts in Centralised recipe @kikofernandez

    3ddf4 origin/master Github 3ddf4 HEAD master 3eba4 origin/master origin/master $ git push origin master $ git commit -am “stuff” $ git commit -am “work” $ git push origin master 12ab56 @kikofernandez @supercooldave @supercooldave
  76. 3ddf4 HEAD master 12ab56 26 Conflicts in Centralised recipe @kikofernandez

    3ddf4 origin/master Github 3ddf4 HEAD master 3eba4 origin/master origin/master $ git push origin master $ git commit -am “stuff” $ git commit -am “work” $ git push origin master 12ab56 @kikofernandez @supercooldave @supercooldave error: failed to push some refs to '/path/to/repo.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Merge the remote changes (e.g. 'git pull') hint: before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
  77. 3ddf4 HEAD master 12ab56 26 Conflicts in Centralised recipe @kikofernandez

    3ddf4 origin/master Github 3ddf4 HEAD master 3eba4 origin/master origin/master $ git push origin master $ git commit -am “stuff” $ git commit -am “work” $ git push origin master 12ab56 @kikofernandez @supercooldave @supercooldave
  78. 3ddf4 HEAD master 12ab56 26 Conflicts in Centralised recipe @kikofernandez

    3ddf4 origin/master Github 3ddf4 HEAD master 3eba4 origin/master origin/master $ git push origin master $ git commit -am “stuff” $ git commit -am “work” $ git push origin master 12ab56 @kikofernandez @supercooldave $ git pull origin master @supercooldave
  79. 3ddf4 HEAD master 12ab56 26 Conflicts in Centralised recipe @kikofernandez

    3ddf4 origin/master Github 3ddf4 HEAD master 3eba4 origin/master origin/master $ git push origin master $ git commit -am “stuff” $ git commit -am “work” $ git push origin master 12ab56 @kikofernandez @supercooldave $ git pull origin master 12ab56 87abe @supercooldave
  80. 3ddf4 HEAD master 12ab56 26 Conflicts in Centralised recipe @kikofernandez

    3ddf4 origin/master Github 3ddf4 HEAD master 3eba4 origin/master origin/master $ git push origin master $ git commit -am “stuff” $ git commit -am “work” $ git push origin master 12ab56 @kikofernandez @supercooldave $ git pull origin master 87abe $ git push origin master 12ab56 87abe 3eba4 @supercooldave
  81. Useful links • Conflict example (for you to practice) •

    Git - the simple guide • Github: Bootcamp • Git: Cheatsheet • Learn enough git to be dangerous • CodeSchool: Try git 27
  82. Graphical Interfaces SourceTree GithubDesktop

  83. Summary Introduction to git and Github & Distributed workflows so…

  84. Summary Introduction to git and Github & Distributed workflows so…

    let’s git some fun
  85. Thanks Feedback is welcome (email) or at the end of

    the course