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

Git, GitHub and Open Source

Lorna Mitchell
November 20, 2013

Git, GitHub and Open Source

Lorna Mitchell

November 20, 2013
Tweet

More Decks by Lorna Mitchell

Other Decks in Technology

Transcript

  1. Git, GitHub and Open Source
    Lorna Mitchell, NW DrupalCamp 2013

    View full-size slide

  2. GitHub
    "We make it easier to collaborate with others
    and share your projects with the universe"
    • GitHub is hosted source control, based on
    git
    • Used for many open source projects, also
    good for your own projects
    • Competing alternatives exist

    View full-size slide

  3. How to Get Code from GitHub

    View full-size slide

  4. Find and Fork
    First, find the project and fork it

    View full-size slide

  5. Why Fork?
    • To have your own copy
    • To allow you to share changes without
    having write access
    • It is possible to clone a read-only repository

    View full-size slide

  6. Clone the Repo
    Get the URL you need (https recommended)

    View full-size slide

  7. Clone the Repo
    Clone it

    View full-size slide

  8. Examining Changes with Git

    View full-size slide

  9. Git Log
    This goes to a pager; press 'q' to exit

    View full-size slide

  10. Git Log
    My favourite switches:
    git log --oneline --graph --decorate

    View full-size slide

  11. Stay in Sync

    View full-size slide

  12. Git Remotes
    Your local repo has remotes
    • origin is created by default and points to
    where you cloned from
    • upstream is usually the main project repo
    • Add as many remotes as there are
    collaboration points
    To view remotes: git remote -v

    View full-size slide

  13. Remote and Local Repos

    View full-size slide

  14. Get Upstream Changes
    git pull upstream master

    View full-size slide

  15. Get Upstream Changes

    View full-size slide

  16. Update Your Fork
    Push changes from your local fork to your
    GitHub origin:
    git push
    This defaults to origin but you can also specify
    which branch to push and to where:
    git push upstream develop

    View full-size slide

  17. Update Your Fork

    View full-size slide

  18. Git and Branching
    Branching is quick, easy and efficient. More
    importantly, so is merging!
    Your repo will switch itself to a different branch
    when asked

    View full-size slide

  19. Git Branching Strategies
    Each project will have its own branching
    strategy. You may need to:
    • branch per feature
    • branch per ticket (with
    appropriately-named branches)
    • branch per version

    View full-size slide

  20. Make a Branch
    New branch called experiment:
    git checkout -b experiment
    Push the contents of that branch to your GitHub
    origin:
    git push origin experiment
    Change to an existing branch:
    git checkout otherCoolFeature

    View full-size slide

  21. Make and Share Changes

    View full-size slide

  22. Making Changes in Git
    Changes can be in one of three states

    View full-size slide

  23. Git Status
    Shows various sets of changes
    • Changes staged for commit
    • Modified files
    • Untracked files
    • (Unmodified tracked files aren't shown)

    View full-size slide

  24. Make Changes
    When a file has been changed, run git status

    View full-size slide

  25. Git Diff
    See changes in the working area:
    git diff
    See changes staged for commit:
    git diff --staged

    View full-size slide

  26. Prepare Changes
    Use git add README.md to add the file

    View full-size slide

  27. Some Notes on Committing
    • One feature, many atomic commits, one
    branch
    • Meaningful commit messages
    • Layout/coding standard fixes should be
    separate
    • Git encourages careful preparation of
    commits

    View full-size slide

  28. Commit and Share
    Complete the changeset by committing
    git commit -m "Excellent message here"

    View full-size slide

  29. Commit and Share

    View full-size slide

  30. Commit and Share

    View full-size slide

  31. Your Changes on GitHub
    Since we pushed to GitHub, we can see the
    changes there:

    View full-size slide

  32. Pull Requests
    Literally request someone does a pull from
    your repo!
    They provide:
    • an easy way to see offered changes
    • a great interface for reviewing changes
    • tools for discussion of changes

    View full-size slide

  33. Open a Pull Request
    Go to the new branch you pushed

    View full-size slide

  34. Open a Pull Request
    Check the diff and add a summary

    View full-size slide

  35. Open a Pull Request

    View full-size slide

  36. Open a Pull Request
    You'll get an email when it is updated

    View full-size slide

  37. Contributing to Open Source

    View full-size slide

  38. When to Contribute
    When you can improve a project
    Even a teeny tiny bit

    View full-size slide

  39. Why to Contribute
    To help
    To improve your own skills
    As an excellent hobby

    View full-size slide

  40. How to Contribute
    Projects will publish some information for you
    • Contributor guidelines
    • Contact mechanisms
    • Issue lists
    http://joind.in/about

    View full-size slide

  41. Thanks
    Feedback please!
    Lorna Mitchell, consultant, author, developer
    and trainer, available for interesting projects
    • http://github.com/lornajane
    • @lornajane
    • http://lornajane.net

    View full-size slide