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

Contribute to CakePHP with Git and Github

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

Lorna Mitchell

September 02, 2012
Tweet

More Decks by Lorna Mitchell

Other Decks in Technology

Transcript

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

    • Github: http://github.com/lornajane • Twitter: @lornajane • Web: http://lornajane.net
  2. Centralised Version Control The overall ecosystem with git looks different

    because instead of this: repo checkout checkout checkout
  3. Supporting Distributed Workflows Need to keep track of: • Commits

    on other repos • Relationships between repos • Patches (pull requests)
  4. 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
  5. 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 ...
  6. Get a Repo • Find the project • Fork the

    project • Clone your repo
  7. Clone your Repo git clone [email protected]:lornajane/docs.git docs cd docs git

    add remote upstream git://github.com/cakephp/docs.git
  8. 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
  9. Git Log Git automatically sends the output to a pager

    like less commit ae04d50d592aeb8605d28f352cee104b167c998f Merge: 670e31d 93a0f5a Author: Mark Story <[email protected]> Date: Sun Aug 12 20:37:27 2012 -0700 Merge pull request #332 from okonomi/ja-translation-welcome commit 93a0f5a685f919deaf12571aaf1169db76ae8ce7 Author: okonomi <[email protected]> Date: Sun Aug 12 18:27:28 2012 +0900 PDF link change to en. commit 670e31d1d8de5c58c23b57fb4e7a1dc02b698b6e Author: Jose Lorenzo Rodriguez <[email protected]> Date: Sun Aug 12 00:05:12 2012 +0200 Fixing almost all errors in fr translation files
  10. 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
  11. 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
  12. 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 #
  13. 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
  14. 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
  15. Stay in Sync Pull the changes from upstream into your

    local repo GitHub lornajane/docs development changes upstream pull git pull upstream master
  16. 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
  17. Branching in Git What you need to know: • Branching

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

    (and merging!) are fast and painless • Branches are private by default
  19. 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
  20. 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
  21. 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
  22. 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
  23. Sharing Changes Your changes are in your local branch -

    how do they get into a main project? GitHub lornajane/docs local feature cakephp/docs
  24. Sharing Changes To offer changes upstream, make a pull request

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

    Explain what you have changed, and why. Keep changes atomic.
  26. 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
  27. Where to Begin with Open Source How to get involved:

    • Check for introductory docs • http://book.cakephp.org/2.0/en/contributing.html
  28. 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
  29. 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
  30. 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
  31. 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
  32. Thanks! • https://joind.in/6750 • @lornajane • http://lornajane.net PHPNW - 1st

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