Slide 1

Slide 1 text

Git, Github and Open Source

Slide 2

Slide 2 text

About Me • Lorna Jane Mitchell • Consultant, author, speaker • Github: http://github.com/lornajane • Twitter: @lornajane • Web: http://lornajane.net

Slide 3

Slide 3 text

Source Control: Git

Slide 4

Slide 4 text

The Aims of Source Control • Central keeping-place

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

The Aims of Source Control • Central keeping-place • History of changes • Painless collaboration

Slide 7

Slide 7 text

Centralised Version Control The overall ecosystem with git looks different because instead of this: repo checkout checkout checkout

Slide 8

Slide 8 text

Distributed Version Control Things look like this: repo repo repo repo repo

Slide 9

Slide 9 text

Distributed Version Control Or rather: repo repo repo repo repo

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

GitHub

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

Get a Repo • Find the project • Fork the project • Clone your repo

Slide 15

Slide 15 text

Fork the Project https://github.com/cakephp/docs

Slide 16

Slide 16 text

Clone your Repo git clone [email protected]:lornajane/docs.git docs cd docs git add remote upstream git://github.com/cakephp/docs.git

Slide 17

Slide 17 text

Git: Many Repos GitHub lornajane/docs development cakephp/docs clone fork

Slide 18

Slide 18 text

Working with Git

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

Git Log Git automatically sends the output to a pager like less commit ae04d50d592aeb8605d28f352cee104b167c998f Merge: 670e31d 93a0f5a Author: Mark Story Date: Sun Aug 12 20:37:27 2012 -0700 Merge pull request #332 from okonomi/ja-translation-welcome commit 93a0f5a685f919deaf12571aaf1169db76ae8ce7 Author: okonomi Date: Sun Aug 12 18:27:28 2012 +0900 PDF link change to en. commit 670e31d1d8de5c58c23b57fb4e7a1dc02b698b6e Author: Jose Lorenzo Rodriguez Date: Sun Aug 12 00:05:12 2012 +0200 Fixing almost all errors in fr translation files

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

Git Status $ git status # On branch style-table-name # Changes not staged for commit: # (use "git add ..." to update what will be committed) # (use "git checkout -- ..." 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

Slide 23

Slide 23 text

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 ..." to unstage) # # modified: en/getting-started/cakephp-conventions.rst #

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

Managing the Multiple Repositories

Slide 27

Slide 27 text

Stay in Sync Pull the changes from upstream into your local repo GitHub lornajane/docs development changes upstream pull git pull upstream master

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

Sharing Changes Your changes are in your local branch - how do they get into a main project? GitHub lornajane/docs local feature cakephp/docs

Slide 36

Slide 36 text

Sharing Changes git push origin new-branch-name GitHub feature at origin local feature cakephp/docs push

Slide 37

Slide 37 text

Sharing Changes To offer changes upstream, make a pull request GitHub feature at origin local feature cakephp/docs pull request

Slide 38

Slide 38 text

Making a Pull Request Make the pull request on GitHub Explain what you have changed, and why. Keep changes atomic.

Slide 39

Slide 39 text

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

Slide 40

Slide 40 text

Pull Request Accepted Your pull request may be commented on, rejected or merged

Slide 41

Slide 41 text

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

Slide 42

Slide 42 text

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

Slide 43

Slide 43 text

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

Slide 44

Slide 44 text

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

Slide 45

Slide 45 text

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

Slide 46

Slide 46 text

Questions?

Slide 47

Slide 47 text

Thanks! • https://joind.in/6750 • @lornajane • http://lornajane.net PHPNW - 1st Tuesday each month, in Manchester http://twitter.com/phpnw