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

Git and Github: Working effectively on a team

Jeff Carouth
March 15, 2014
510

Git and Github: Working effectively on a team

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. - See more at: http://midwestphp.org/sessions/#sthash.9ur0tXHt.dpuf

Jeff Carouth

March 15, 2014
Tweet

Transcript

  1. git and github
    working effectively on a team
    PRESENTED BY
    JEFF CAROUTH
    @jcarouth

    View full-size slide

  2. Do You use git?
    How long?

    View full-size slide

  3. repository
    A set of commit objects stored next to
    the project files in a .git subdirectory.

    View full-size slide

  4. Remote
    A copy of a repository stored in a
    separate location. Typically this will be on
    the Internet or over the network
    somewhere.

    View full-size slide

  5. push
    The act of updating a remote repository
    with commit objects from a local
    repository.

    View full-size slide

  6. merge
    The act of bringing commit objects from
    one branch to another. This can be local
    or remote.

    View full-size slide

  7. pull request
    Proposed changes to a repository
    submitted by a user and either accepted
    or rejected by a project member.

    View full-size slide

  8. git push
    Publish a set of commit objects to the
    remote. If you want to be explicit you can
    specify the remote and branch to which
    you wish to push.

    View full-size slide

  9. git push
    git push!
    git push origin master!
    git push

    View full-size slide

  10. git fetch
    Download commit objects from a remote
    into the local repository. This does not
    apply any changes to your workspace.

    View full-size slide

  11. git fetch
    git fetch!
    git fetch origin master!
    git fetch !
    git fetch

    View full-size slide

  12. git merge
    Apply a set of change objects to your
    workspace. This can reference a local
    branch or a remote branch.

    View full-size slide

  13. git merge
    git merge my-branch!
    git merge origin/master

    View full-size slide

  14. git pull
    Incorporate changes from a remote
    repository and branch into the workspace.
    This operation is effectively a

    git fetch followed by a git merge.

    View full-size slide

  15. git pull
    git pull!
    git pull origin master

    View full-size slide

  16. git rebase
    Apply changes to the current branch on
    top of the specified branch’s history.

    View full-size slide

  17. git rebase
    git rebase origin/master!
    git rebase master!
    git rebase

    View full-size slide

  18. git rebase
    git rebase --interactive HEAD~3

    View full-size slide

  19. ! 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

    View full-size slide

  20. ! git rebase --interactive HEAD~4

    View full-size slide

  21. pick 0c9a579 Add Foo documentation!
    pick 991241d Update foo!
    pick ec08733 Expand idea of foo with speakers!
    pick 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

    View full-size slide

  22. 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

    View full-size slide

  23. ! 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.

    View full-size slide

  24. ! 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

    View full-size slide

  25. 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”.

    View full-size slide

  26. git commit
    Record a change to the local repository.
    This change then shows up in the history
    and has a hash reference, a message, and a
    set of changes.

    View full-size slide

  27. git commit
    git commit -m “Summary”!
    git commit --amend!
    git commit --fixup=HEAD

    View full-size slide

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

    View full-size slide

  29. Feature Branch

    View full-size slide

  30. master
    feature

    View full-size slide

  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 fetch!
    git rebase origin/master!
    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 fetch!
    git rebase origin/master!
    git push origin feature-b

    View full-size slide

  32. master
    feature-a
    feature-b

    View full-size slide

  33. Developer 1 (John)
    git fetch!
    git checkout master!
    git merge origin/feature-b!
    git push origin :feature-b!
    git push origin master

    View full-size slide

  34. master
    feature-a

    View full-size slide

  35. Developer 1 (John)
    git checkout feature-a!
    git fetch!
    git rebase origin/master!
    git checkout master!
    git merge feature-a!
    git push origin master!
    git push origin :feature-a

    View full-size slide

  36. code reviews and
    conversations

    View full-size slide

  37. pull requests
    for code review

    View full-size slide

  38. 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

    View full-size slide

  39. Pull Requests:
    Open Early;
    Update often.

    View full-size slide

  40. Tip
    When incorporating feedback
    in your Pull Request, use
    autosquash or rebase your
    commits before merging.

    View full-size slide

  41. 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

    View full-size slide

  42. Incorporate feedback
    vim public/index.php!
    git add public/index.php!
    git commit --fixup=HEAD!
    git push origin base-controller

    View full-size slide

  43. 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

    View full-size slide

  44. Rebase to clean up our commits
    git rebase --interactive origin/master

    View full-size slide

  45. Rebase to clean up our commits
    pick 6b322a2 Add base controller!
    fixup 00340d4 fixup! Add base controller!
    !
    # Rebase a8d7c57..00340d4 onto a8d7c57!
    #!
    # 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

    View full-size slide

  46. 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!

    View full-size slide

  47. 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 [email protected]:jcarouth/git-sample-repo.git!
    + 00340d4...8adf92e base-controller -> base-controller (forced
    update)

    View full-size slide

  48. Experimental code
    Branching off Branches

    View full-size slide

  49. 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

    View full-size slide

  50. Working on a feature

    View full-size slide

  51. Branch off a branch
    • Start work by creating a branch off of master

    View full-size slide

  52. Branch off a branch
    • Start work by creating a branch off of master!
    • Make a change

    View full-size slide

  53. Branch off a branch
    • Start work by creating a branch off of master!
    • Make a change!
    • Commit it with a message for the whole feature

    View full-size slide

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

    View full-size slide

  55. Branch off a branch
    • 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

    View full-size slide

  56. Branch off a branch
    • 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

    View full-size slide

  57. Branch off a branch
    • 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.

    View full-size slide

  58. Branch off a branch
    • 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)

    View full-size slide

  59. Branch off a branch
    • 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

    View full-size slide

  60. Branch off a branch
    • 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!
    • Rebase against master

    View full-size slide

  61. Branch off a branch
    • 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!
    • Rebase against master!
    • Force push

    View full-size slide

  62. Branch off a branch
    • 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!
    • Rebase against master!
    • Force push!
    • Update PR that it's ready for merge

    View full-size slide

  63. Branch off a branch
    • 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!
    • Rebase against master!
    • Force push!
    • Update PR that it's ready for merge!
    • Following policy, merge the PR

    View full-size slide

  64. Branch off a branch
    • 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!
    • Rebase against master!
    • Force push!
    • Update PR that it's ready for merge!
    • Following policy, merge the PR

    View full-size slide

  65. Push your code regularly.
    Takeaways

    View full-size slide

  66. Open Pull Requests early.
    Update them often.!
    They’re free, after all.
    Takeaways

    View full-size slide

  67. 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

    View full-size slide