Git and Github: Working Effectively on a Team at php[tek] 2014

Git and Github: Working Effectively on a Team at php[tek] 2014

Git is great. Project hosting on Github is even better. But how does git fit into your team workflow? In this talk we will cover how to effectively use git as your source control management system from an individual developer's perspective and then from a team perspective. You will learn how to efficiently use git during feature implementation and experimentation including stashing, committing, rebasing, and code sharing techniques; how you can leverage Github to spur conversations about code and implementation; and a workflow incorporating code review using Github's pull requests.

0f930e13633535c1c4041e95b8881308?s=128

Jeff Carouth

May 23, 2014
Tweet

Transcript

  1. git and github working effectively on a team PRESENTED BY

    JEFF CAROUTH @jcarouth
  2. Do You use git? How long?

  3. Effectively working on a team requires communication

  4. Email is not effective communication

  5. Opportunities for Communication

  6. Opportunities for Communication 1. Commit messages

  7. Opportunities for Communication 1. Commit messages 2. Pull request comments

  8. Opportunities for Communication 1. Commit messages 2. Pull request comments

    3. Commit comments
  9. Opportunities for Communication 1. Commit messages 2. Pull request comments

    3. Commit comments 4. Issue tracker
  10. Opportunities for Communication 1. Commit messages 2. Pull request comments

    3. Commit comments 4. Issue tracker 5. <everything else>
  11. Commands

  12. git rebase Apply changes to the current branch on top

    of the specified branch’s history.
  13. git rebase git rebase origin/master! git rebase master! git rebase

    <branch>
  14. git rebase git rebase --interactive HEAD~3

  15. ! git log --graph --pretty=oneline --abbrev-commit! * 9f65212 Fix typos!

    * ec08733 Expand idea of foo with speakers! * 991241d Update foo! * 0c9a579 Add Foo documentation! * 9a42a76 Combine sentences into paragraph! * 63d250a Add more detail to the README! * a14a778 Update summary to be more descriptive! * 0722e78 Initial commit
  16. ! git rebase --interactive HEAD~4

  17. 1 pick 0c9a579 Add Foo documentation! 2 pick 991241d Update

    foo! 3 pick ec08733 Expand idea of foo with speakers! 4 pick 9f65212 Fix typos! 5! 6 # Rebase 9a42a76..9f65212 onto 9a42a76! 7 #! 8 # Commands:! 9 # p, pick = use commit! 10 # r, reword = use commit, but edit the commit message! 11 # e, edit = use commit, but stop for amending! 12 # s, squash = use commit, but meld into previous commit! 13 # f, fixup = like "squash", but discard this commit's log message! 14 # x, exec = run command (the rest of the line) using shell! 15 #! 16 # These lines can be re-ordered; they are executed from top to bottom.! 17 #! 18 # If you remove a line here THAT COMMIT WILL BE LOST.! 19 #! 20 # However, if you remove everything, the rebase will be aborted.! 21 #! 22 # Note that empty commits are commented out
  18. pick 0c9a579 Add Foo documentation! fixup 991241d Update foo! pick

    ec08733 Expand idea of foo with speakers! fixup 9f65212 Fix typos! ! # Rebase 9a42a76..9f65212 onto 9a42a76! #! # Commands:! # p, pick = use commit! # r, reword = use commit, but edit the commit message! # e, edit = use commit, but stop for amending! # s, squash = use commit, but meld into previous commit! # f, fixup = like "squash", but discard this commit's log message! # x, exec = run command (the rest of the line) using shell! #! # These lines can be re-ordered; they are executed from top to bottom.! #! # If you remove a line here THAT COMMIT WILL BE LOST.! #! # However, if you remove everything, the rebase will be aborted.! #! # Note that empty commits are commented out
  19. ! git rebase --interactive HEAD~4! [detached HEAD 9c02248] Add Foo

    documentation! 1 file changed, 3 insertions(+)! create mode 100644 foo.md! [detached HEAD 47613fd] Expand idea of foo with speakers! 1 file changed, 1 insertion(+), 1 deletion(-)! Successfully rebased and updated refs/heads/master.
  20. ! git log --graph --pretty=oneline --abbrev-commit! * 47613fd Expand idea

    of foo with speakers! * 9c02248 Add Foo documentation! * 9a42a76 Combine sentences into paragraph! * 63d250a Add more detail to the README! * a14a778 Update summary to be more descriptive! * 0722e78 Initial commit
  21. git pull --rebase The same as git pull, but instead

    of doing a merge operation after a fetch, it does a rebase. This is useful to keep your history clean of “merge commits”.
  22. workflows

  23. centralized

  24. None
  25. Developer 1 (John) git clone org/repo.git! vim file.md! git pull!

    git add file.md! git commit -m “Add file”! git push origin master
  26. Developer 1 (John) Developer 2 (Jane) git clone org/repo.git! vim

    file.md! git pull! git add file.md! git commit -m “Add file”! git push origin master git clone org/repo.git! vim foo.md! git pull! git add foo.md! git commit -m “Add foo”! git push origin master
  27. master

  28. Feature Branch

  29. None
  30. Developer 1 (John) git clone org/repo.git! git checkout -b feature-a!

    vim file.md! git add file.md! git commit -m “Add file”! git push origin feature-a
  31. Developer 1 (John) Developer 2 (Jane) git clone org/repo.git! git

    checkout -b feature-a! vim file.md! git add file.md! git commit -m “Add file”! git push origin feature-a git clone org/repo.git! git checkout -b feature-b! vim foo.md! git add foo.md! git commit -m “Add foo”! git push origin feature-b
  32. master feature-a feature-b

  33. Developer 1 (John) git fetch! git checkout master! git merge

    origin/feature-b! git push origin :feature-b! git push origin master
  34. master feature-a

  35. Developer 1 (John) git checkout feature-a! git fetch! git checkout

    master! git merge feature-a! git push origin master! git push origin :feature-a
  36. master master

  37. Git Flow

  38. None
  39. rebase vs. merge

  40. Developer 1 (bar) ! vim bar.md! ! git add .!

    ! git commit -m "Add bar"! [master 3ab9ff9] Add bar! 1 file changed, 1 insertion(+)! create mode 100644 bar.md! ! vim bar.md! ! git add .! ! git commit -m "Add bar docs"! [master cef18d5] Add what is statement to bar docs! 1 file changed, 2 insertions(+)
  41. Developer 1 (bar) ! vim bar.md! ! git add .!

    ! git commit -m "Add bar"! [master 3ab9ff9] Add bar! 1 file changed, 1 insertion(+)! create mode 100644 bar.md! ! vim bar.md! ! git add .! ! gc -m "Add what is statement to bar docs"! [master cef18d5] Add what is statement to bar docs! 1 file changed, 2 insertions(+) Developer 2 (baz) ! vim baz.md! ! git add .! ! git commit -m "Add baz"! [feature-b 57b25fb] Add baz! 1 file changed, 1 insertion(+)! create mode 100644 baz.md!
  42. Developer 1 (bar) Developer 2 (baz) ! git fetch origin!

    From origin! 0066729..cef18d5 master -> origin/master! ! git pull origin master! From origin! * branch master -> FETCH_HEAD! Merge made by the 'recursive' strategy.! bar.md | 3 +++! file.md | 1 +! 2 files changed, 4 insertions(+)! create mode 100644 bar.md! create mode 100644 file.md
  43. Developer 1 (bar) Developer 2 (baz) ! vim baz.md! !

    git add .! ! git commit -m "Clarify baz's coolness"! [feature-b c7c084f] Clarify baz's coolness! 1 file changed, 2 insertions(+)!
  44. Developer 1 (bar) Developer 2 (baz) ! git push origin

    feature-c! Total 8 (delta 3), reused 0 (delta 0)! To origin! * [new branch] feature-c -> feature-c
  45. Developer 1 (bar) Developer 2 (baz) ! git checkout master!

    ! git merge feature-c! Updating cef18d5..c7c084f! Fast-forward! baz.md | 3 +++! 1 file changed, 3 insertions(+)! create mode 100644 baz.md! ! git push origin master
  46. master master

  47. master master

  48. master master Merge branch 'master' of origin into feature-b

  49. Developer 1 (bar) Developer 2 (baz) ! git fetch origin!

    From origin! 0066729..cef18d5 master -> origin/master! ! git pull origin master! From origin! * branch master -> FETCH_HEAD! Merge made by the 'recursive' strategy.! bar.md | 3 +++! file.md | 1 +! 2 files changed, 4 insertions(+)! create mode 100644 bar.md! create mode 100644 file.md
  50. Developer 1 (bar) Developer 2 (baz) ! git fetch origin!

    From origin! 0066729..cef18d5 master -> origin/master! ! git pull origin master! From origin! * branch master -> FETCH_HEAD! Merge made by the 'recursive' strategy.! bar.md | 3 +++! file.md | 1 +! 2 files changed, 4 insertions(+)! create mode 100644 bar.md! create mode 100644 file.md! ! vim baz.md! ! git add .! ! git commit -m "Clarify baz's coolness"! [feature-b c7c084f] Clarify baz's coolness! 1 file changed, 2 insertions(+)
  51. Developer 1 (bar) Developer 2 (baz) ! git fetch origin!

    From origin! 0066729..cef18d5 master -> origin/master! ! git rebase origin/master! First, rewinding head to replay your work on top of it...! Applying: Add buzz! Applying: Add buzz lightyear definition
  52. Developer 1 (bar) Developer 2 (baz) ! git push origin

    feature-d
  53. Developer 1 (bar) Developer 2 (baz) ! git checkout master!

    ! git merge feature-c! Updating cef18d5..c7c084f! Fast-forward! baz.md | 3 +++! 1 file changed, 3 insertions(+)! create mode 100644 baz.md! ! git push origin master
  54. master master

  55. code reviews and conversations

  56. pull requests for code review

  57. New Feature: Lorem Ipsum git checkout -b lorem-ipsum! vim lorem.md!

    git add lorem.md! git commit -m “Add Lorem Ipsum”! git push origin lorem-ipsum
  58. None
  59. None
  60. Pull Requests: Open Early; Update often.

  61. Tip When incorporating feedback in your Pull Request, use autosquash

    or rebase your commits before merging.
  62. Add controller for Slim application git checkout -b base-controller! vim

    public/index.php! git add public/index.php! git commit -m “Add slim controller”! git push origin base-controller
  63. None
  64. None
  65. Incorporate feedback vim public/index.php! git add public/index.php! git commit --fixup=HEAD!

    git push origin base-controller
  66. None
  67. History ! git log --graph --pretty=oneline --abbrev-commit! * 00340d4 fixup!

    Add base controller! * 6b322a2 Add base controller! * a8d7c57 Merge pull request #1 from jcarouth/lorem! |\! | * ba68860 Add Lorem Ipsum! |/! * e81ce07 Add file! * 0a4cfa4 Add phone! * aa0f561 Add bar! * f387f9e Add new! * a770a30 More updates! * 6045962 Updates! * 56db6d5 fixup! Expand idea of foo with speakers! * 47613fd Expand idea of foo with speakers! * 9c02248 Add Foo documentation! * 9a42a76 Combine sentences into paragraph! * 63d250a Add more detail to the README! * a14a778 Update summary to be more descriptive! * 0722e78 Initial commit
  68. Rebase to clean up our commits git rebase --interactive origin/master

  69. Rebase to clean up our commits 1 pick 6b322a2 Add

    base controller! 2 fixup 00340d4 fixup! Add base controller! 3! 4 # Rebase a8d7c57..00340d4 onto a8d7c57! 5 #! 6 # Commands:! 7 # p, pick = use commit! 8 # r, reword = use commit, but edit the commit message! 9 # e, edit = use commit, but stop for amending! 10 # s, squash = use commit, but meld into previous commit! 11 # f, fixup = like "squash", but discard this commit's log message! 12 # x, exec = run command (the rest of the line) using shell! 13 #! 14 # These lines can be re-ordered; they are executed from top to bottom.! 15 #! 16 # If you remove a line here THAT COMMIT WILL BE LOST.! 17 #! 18 # However, if you remove everything, the rebase will be aborted.! 19 #! 20 # Note that empty commits are commented out
  70. History ! git rebase --interactive origin/master! [detached HEAD 8adf92e] Add

    base controller! 1 file changed, 17 insertions(+)! create mode 100644 public/index.php! Successfully rebased and updated refs/heads/base-controller.! ! ! git log --graph --pretty=oneline --abbrev-commit! * 8adf92e Add base controller! * a8d7c57 Merge pull request #1 from jcarouth/lorem! |\! | * ba68860 Add Lorem Ipsum! |/! * e81ce07 Add file! * 0a4cfa4 Add phone! …
  71. Push to origin (requires force) ! git push -f origin

    base-controller! Counting objects: 1, done.! Writing objects: 100% (1/1), 195 bytes | 0 bytes/s, done.! Total 1 (delta 0), reused 0 (delta 0)! To git@github.com:jcarouth/git-sample-repo.git! + 00340d4...8adf92e base-controller -> base-controller (forced update)
  72. None
  73. Experimental code Branching off Branches

  74. None
  75. Branch off a branch git fetch! git checkout retrieve-user! git

    checkout -b use-doctrineserviceprovider! vim public/index.php! git add public/index.php! git commit -m “Use DoctringServiceProvider”! git push origin use-doctrineserviceprovider
  76. None
  77. None
  78. Working on a feature

  79. My general workflow • Start work by creating a branch

    off of master
  80. My general workflow • Start work by creating a branch

    off of master! • Make a change
  81. My general workflow • Start work by creating a branch

    off of master! • Make a change! • Commit it with a message for the whole feature
  82. My general workflow • Start work by creating a branch

    off of master! • Make a change! • Commit it with a message for the whole feature! • Make more changes
  83. My general workflow • Start work by creating a branch

    off of master! • Make a change! • Commit it with a message for the whole feature! • Make more changes! • Either commit --amend or commit using fixup
  84. My general workflow • Start work by creating a branch

    off of master! • Make a change! • Commit it with a message for the whole feature! • Make more changes! • Either commit --amend or commit using fixup! • Push work to the remote
  85. My general workflow • Start work by creating a branch

    off of master! • Make a change! • Commit it with a message for the whole feature! • Make more changes! • Either commit --amend or commit using fixup! • Push your work to the remote! • Open PR for visibility. Tag people to notify them.
  86. My general workflow • Start work by creating a branch

    off of master! • Make a change! • Commit it with a message for the whole feature! • Make more changes! • Either commit --amend or commit using fixup! • Push your work to the remote! • Open PR for visibility. Tag people to notify them.! • Incorporate feedback as commits (fixup is nice here)
  87. My general workflow • Start work by creating a branch

    off of master! • Make a change! • Commit it with a message for the whole feature! • Make more changes! • Either commit --amend or commit using fixup! • Push your work to the remote! • Open PR for visibility. Tag people to notify them.! • Incorporate feedback as commits (fixup is nice here)! • When all feedback is incorporated, rebase against master
  88. My general workflow • Start work by creating a branch

    off of master! • Make a change! • Commit it with a message for the whole feature! • Make more changes! • Either commit --amend or commit using fixup! • Push your work to the remote! • Open PR for visibility. Tag people to notify them.! • Incorporate feedback as commits (fixup is nice here)! • When all feedback is incorporated, rebase against master! • Force push the branch
  89. My general workflow • Start work by creating a branch

    off of master! • Make a change! • Commit it with a message for the whole feature! • Make more changes! • Either commit --amend or commit using fixup! • Push your work to the remote! • Open PR for visibility. Tag people to notify them.! • Incorporate feedback as commits (fixup is nice here)! • When all feedback is incorporated, rebase against master! • Force push the branch! • Update PR that it's ready for merge
  90. My general workflow • Start work by creating a branch

    off of master! • Make a change! • Commit it with a message for the whole feature! • Make more changes! • Either commit --amend or commit using fixup! • Push your work to the remote! • Open PR for visibility. Tag people to notify them.! • Incorporate feedback as commits (fixup is nice here)! • When all feedback is incorporated, rebase against master! • Force push the branch! • Update PR that it's ready for merge! • Following policy, merge the PR
  91. My general workflow • Start work by creating a branch

    off of master! • Make a change! • Commit it with a message for the whole feature! • Make more changes! • Either commit --amend or commit using fixup! • Push your work to the remote! • Open PR for visibility. Tag people to notify them.! • Incorporate feedback as commits (fixup is nice here)! • When all feedback is incorporated, rebase against master! • Force push! • Update PR that it's ready for merge! • Following policy, merge the PR
  92. Profit.

  93. resources

  94. help.github.com

  95. training.github.com

  96. www.atlassian.com/git/workflows

  97. Push your code regularly. Takeaways

  98. Open Pull Requests early. Update them often.! They’re free, after

    all. Takeaways
  99. Rebase-ing is not scary. Rebasing shared branches can be problematic,

    but be aware of what you’re doing and you’ll be alright. (Or you might have a bad time.) Takeaways
  100. Thank You joind.in/10636 @jcarouth