Contribute to CakePHP with Git and Github

D33d8bdd9096c80b8d1acca8d28410b5?s=47 Lorna Mitchell
September 02, 2012

Contribute to CakePHP with Git and Github

CakeFest session from Manchester 2012, showing how to get into open source using git and github

D33d8bdd9096c80b8d1acca8d28410b5?s=128

Lorna Mitchell

September 02, 2012
Tweet

Transcript

  1. Git, Github and Open Source

  2. About Me • Lorna Jane Mitchell • Consultant, author, speaker

    • Github: http://github.com/lornajane • Twitter: @lornajane • Web: http://lornajane.net
  3. Source Control: Git

  4. The Aims of Source Control • Central keeping-place

  5. The Aims of Source Control • Central keeping-place • History

    of changes
  6. The Aims of Source Control • Central keeping-place • History

    of changes • Painless collaboration
  7. Centralised Version Control The overall ecosystem with git looks different

    because instead of this: repo checkout checkout checkout
  8. Distributed Version Control Things look like this: repo repo repo

    repo repo
  9. Distributed Version Control Or rather: repo repo repo repo repo

  10. Supporting Distributed Workflows Need to keep track of: • Commits

    on other repos • Relationships between repos • Patches (pull requests)
  11. Supporting Distributed Workflows Need to keep track of: • Commits

    on other repos • Relationships between repos • Patches (pull requests) Often: source browsing, documentation and issue trackers are also included
  12. GitHub

  13. Github "We make it easier to collaborate with others and

    share your projects with the universe" • Github is a hosted source control solution, based on git. • Used by open source projects, personal projects • Paid-for offerings for non-public code There are other ways to do git, open source, and probably everything mentioned here ...
  14. Get a Repo • Find the project • Fork the

    project • Clone your repo
  15. Fork the Project https://github.com/cakephp/docs

  16. Clone your Repo git clone git@github.com:lornajane/docs.git docs cd docs git

    add remote upstream git://github.com/cakephp/docs.git
  17. Git: Many Repos GitHub lornajane/docs development cakephp/docs clone fork

  18. Working with Git

  19. Git Overview A few key commands you will need: •

    git log and git show • git status and git diff • git add • git commit • git pull and git push • reverting changes Then we’ll talk about branching
  20. Git Log Git automatically sends the output to a pager

    like less commit ae04d50d592aeb8605d28f352cee104b167c998f Merge: 670e31d 93a0f5a Author: Mark Story <mark@mark-story.com> Date: Sun Aug 12 20:37:27 2012 -0700 Merge pull request #332 from okonomi/ja-translation-welcome commit 93a0f5a685f919deaf12571aaf1169db76ae8ce7 Author: okonomi <oknm@okonomi.sakura.ne.jp> Date: Sun Aug 12 18:27:28 2012 +0900 PDF link change to en. commit 670e31d1d8de5c58c23b57fb4e7a1dc02b698b6e Author: Jose Lorenzo Rodriguez <jose.zap@gmail.com> Date: Sun Aug 12 00:05:12 2012 +0200 Fixing almost all errors in fr translation files
  21. Git Log There are some alternative views, this is git

    log -graph -oneline $ git log --graph --oneline * ae04d50 Merge pull request #332 from okonomi/ja-translation-welcom |\ | * 93a0f5a PDF link change to en. | * fb76e8a Merge branch 'master' into ja-translation-welcome | |\ | * | 721a8a7 wording small adjustment | * | 1263270 added offline-download container * | | 670e31d Fixing almost all errors in fr translation files * | | 81d7c2e Fixes for PHP 5.4 Strict Warnings * | | 81427d1 Merge pull request #335 from reinoldus/patch-1 |\ \ \ | * | | 2f68a03 Update en/tutorials-and-examples/simple-acl-controlled |/ / / * | | 82e7760 Adding French to the list of languages for the book * | | 3c984d1 Restoring gitignore * | | 0e4553a Merge pull request #334 from cake17/master
  22. Git Status $ git status # On branch style-table-name #

    Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working dir # # modified: en/getting-started/cakephp-conventions.rst # no changes added to commit (use "git add" and/or "git commit -a") To include changes in a commit, we need to stage them first using git add
  23. Git Add git add en/getting-started/cakephp-conventions.rst git status again $ git

    status # On branch style-table-name # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: en/getting-started/cakephp-conventions.rst #
  24. Git Commit git commit -m ’meaningful commit message’ • Without

    the -m, git will open your default text editor to add a message • You can also supply a list of files to include in the commit • Use git add -interactive to stage sections of files
  25. Undoing Changes To undo changes that you haven’t staged yet:

    git checkout -- path/to/file If you have staged the changes, you can still undo them: git reset git reset --hard Reset will unstage the changes; the hard reset puts everything back to the most recent commit
  26. Managing the Multiple Repositories

  27. Stay in Sync Pull the changes from upstream into your

    local repo GitHub lornajane/docs development changes upstream pull git pull upstream master
  28. Stay in Sync The changes are now in your local

    repo, push them to github: GitHub lornajane/docs changes locally changes upstream push git push
  29. Branching in Git What you need to know: • Branching

    (and merging!) are fast and painless
  30. Branching in Git What you need to know: • Branching

    (and merging!) are fast and painless • Branches are private by default
  31. Branching in Git What you need to know: • Branching

    (and merging!) are fast and painless • Branches are private by default • Branches are in the repo, they are not copies • no updating vhosts • only one directory with code in
  32. Git Branching Commands Create a new branch: git checkout -b

    new-branch-name Switch to an existing branch git checkout branchname List branches in this repo git branch Branches are local by default, they don’t synchronise to other repositories unless asked
  33. Best Practice in Branching Git doesn’t dictate a process, so

    usually each project does. Common features: • Branch for features • Branch for fixes • Branch for experiments
  34. Best Practice in Branching Git doesn’t dictate a process, so

    usually each project does. Common features: • Branch for features • Branch for fixes • Branch for experiments • Basically: branch! By keeping changes in branches, they are very easy to merge to another repo or branch
  35. Sharing Changes Your changes are in your local branch -

    how do they get into a main project? GitHub lornajane/docs local feature cakephp/docs
  36. Sharing Changes git push origin new-branch-name GitHub feature at origin

    local feature cakephp/docs push
  37. Sharing Changes To offer changes upstream, make a pull request

    GitHub feature at origin local feature cakephp/docs pull request
  38. Making a Pull Request Make the pull request on GitHub

    Explain what you have changed, and why. Keep changes atomic.
  39. Open Source Contributions After that: • Your pull request appears

    on the project’s list • https://github.com/cakephp/docs/pulls • Hopefully it gets merged • You get bragging rights :) • https://github.com/cakephp/docs/contributors
  40. Pull Request Accepted Your pull request may be commented on,

    rejected or merged
  41. Where to Begin with Open Source How to get involved:

    • Check for introductory docs • http://book.cakephp.org/2.0/en/contributing.html
  42. Where to Begin with Open Source How to get involved:

    • Check for introductory docs • http://book.cakephp.org/2.0/en/contributing.html • Get code and set up the project • usually, fork the repo and read the README
  43. Where to Begin with Open Source How to get involved:

    • Check for introductory docs • http://book.cakephp.org/2.0/en/contributing.html • Get code and set up the project • usually, fork the repo and read the README • Find the bug tracker, and pick something • http://cakephp.lighthouseapp.com
  44. Where to Begin with Open Source How to get involved:

    • Check for introductory docs • http://book.cakephp.org/2.0/en/contributing.html • Get code and set up the project • usually, fork the repo and read the README • Find the bug tracker, and pick something • http://cakephp.lighthouseapp.com • Talk to the other people in the project • #cakephp on freenode
  45. Where to Begin with Open Source How to get involved:

    • Check for introductory docs • http://book.cakephp.org/2.0/en/contributing.html • Get code and set up the project • usually, fork the repo and read the README • Find the bug tracker, and pick something • http://cakephp.lighthouseapp.com • Talk to the other people in the project • #cakephp on freenode • Share and enjoy
  46. Questions?

  47. Thanks! • https://joind.in/6750 • @lornajane • http://lornajane.net PHPNW - 1st

    Tuesday each month, in Manchester http://twitter.com/phpnw