git, github and open source

40
Git, Github and Open Source

Upload: lorna-mitchell

Post on 07-May-2015

2.721 views

Category:

Technology


0 download

DESCRIPTION

How to get involved with an open source project using github. Shows the process of forking and cloning, a bit of a git primer, and how to submit pull requests. Also how to approach and contribute to an open source project.

TRANSCRIPT

Page 1: Git, GitHub and Open Source

Git, Github and Open Source

Page 2: Git, GitHub and Open Source

About Me

2

• Lorna Jane Mitchell

• Consultant, author, speaker

• Github: http://github.com/lornajane

• Twitter: @lornajane

• Web: http://lornajane.net

• Project lead of joind.in , open source project

Page 3: Git, GitHub and Open Source

Github

3

"We make it easier to collaborate with others and share your projects withthe 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 everythingmentioned here ...

Page 4: Git, GitHub and Open Source

Centralised Version Control

4

The overall ecosystem with git looks different because instead of this:

repo

checkout checkoutcheckout

Page 5: Git, GitHub and Open Source

Distributed Version Control

5

Things look like this:

repo

repo reporepo repo

Page 6: Git, GitHub and Open Source

Distributed Version Control

6

Or rather:

repo

repo

repo

repo

repo

Page 7: Git, GitHub and Open Source

Code on GitHub

Page 8: Git, GitHub and Open Source

Get a Repo

8

• Find the project

• Fork the project

• Clone your repo

Page 9: Git, GitHub and Open Source

Fork the Project

9https://github.com/joindin/joind.in

Page 10: Git, GitHub and Open Source

Clone your Repo

10

git clone [email protected]:username/joindin.git

Page 11: Git, GitHub and Open Source

Git: Many Repos

11

GitHub

your-user/joind.in

development

joindin/joind.in

clone

fork

Page 12: Git, GitHub and Open Source

Working with Git

Page 13: Git, GitHub and Open Source

Git Overview

13

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

Page 14: Git, GitHub and Open Source

Git Log

14

Git automatically sends the output to a pager like less

commit 76916fed387d9161d48b0f1e592685c183e4757cAuthor: Lorna Mitchell <[email protected]>Date: Wed Mar 14 21:06:24 2012 +0000

adding the actual announcement wording to the banner

commit 3fdc9f6b9795ed6a3a02465817bfebb8f77ca34eAuthor: Kim Rowan <[email protected] ome>Date: Tue Mar 13 12:58:48 2012 +0000

Added info block to main page announcing php|arch Impact Awa rd nomination

commit dc5777199aa2bb822b498ec1dea99f3e89ee90e0Author: Lorna Mitchell <[email protected]>Date: Sun Mar 11 21:03:13 2012 +0000

removed some unused files

Page 15: Git, GitHub and Open Source

Git Log

15

There are some alternative views, this is git log -graph -oneline

* 76916fe adding the actual announcement wording to the banne r

* 3fdc9f6 Added info block to main page announcing php|arch Im pact Award

* dc57771 removed some unused files

* aa502ec straightening out a problem with API metadata not sh owing up

* 6719b8a GH #473: Refactored ternary to if

* d6a69d7 Merge branch 'joindin-167'|\| * b7effc5 JOINDIN-167: Facebook users without username (thi s is possible

* | 6af9450 JOINDIN-167: reverted removal of facebook login

* | 6249401 Merge branch 'master' of https://github.com/joi ndin/joind|\ \| |/|/|| * 16b31d3 Merge remote-tracking branch 'lornajane/no-face book'| |\| | * 36ee9ea removing facebook login functionality - hopefully temporarily| * | f4a2a73 removing references to the gravatar cache; these a re served| |/| * 83d6c04 Prevented forwarding on to anywhere except this sit e after| * d411358 Merge remote-tracking branch 'mvriel/JOINDIN-16 1_2'

Page 16: Git, GitHub and Open Source

Git Status

16

Shows you what you have changed, and what will be in your next commit(these are two different things)

After editing a couple of files:

# On branch impact-banner# Changes not staged for commit:# (use "git add <file>..." to update what will be committed)# (use "git checkout -- <file>..." to discard changes in work ing directory## modified: src/.htaccess# modified: src/system/application/views/main/index.p hp#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 usingmonogit add

Page 17: Git, GitHub and Open Source

Git Add

17

git add src/system/application/views/main/index.php

git status again

# On branch impact-banner# Changes to be committed:# (use "git reset HEAD <file>..." to unstage)## modified: src/system/application/views/main/index.p hp## Changes not staged for commit:# (use "git add <file>..." to update what will be committed)# (use "git checkout -- <file>..." to discard changes in work ing directory## modified: src/.htaccess#

Page 18: Git, GitHub and Open Source

Git Commit

18

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

Page 19: Git, GitHub and Open Source

Undoing Changes

19

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 resetgit reset --hard

Reset will unstage the changes; the hard reset puts everything back to themost recent commit

Page 20: Git, GitHub and Open Source

Managing the Multiple Repositories

Page 21: Git, GitHub and Open Source

Stay in Sync

21

Pull the changes from upstream into your local repo

GitHub

your-user/joind.in

development

changes upstream

pull

git pull upstream master

Page 22: Git, GitHub and Open Source

Stay in Sync

22

The changes are now in your local repo, push them to github:

GitHub

your-user/joind.in

changes locally

changes upstream

push

git push

Page 23: Git, GitHub and Open Source

Branching in Git

23

What you need to know:

• Branching (and merging!) are fast and painless

Page 24: Git, GitHub and Open Source

Branching in Git

23

What you need to know:

• Branching (and merging!) are fast and painless

• Branches are private by default

Page 25: Git, GitHub and Open Source

Branching in Git

23

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

Page 26: Git, GitHub and Open Source

Git Branching Commands

24

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 repositoriesunless asked

Page 27: Git, GitHub and Open Source

Best Practice in Branching

25

Git doesn’t dictate a process, so usually each project does. Commonfeatures:

• Branch for features

• Branch for fixes

• Branch for experiments

Page 28: Git, GitHub and Open Source

Best Practice in Branching

25

Git doesn’t dictate a process, so usually each project does. Commonfeatures:

• Branch for features

• Branch for fixes

• Branch for experiments

• Basically: branch!

By keeping changes in branches, they are very easy to merge to anotherrepo or branch

Page 29: Git, GitHub and Open Source

Sharing Changes

26

Your changes are in your local branch - how do they get into a mainproject?

GitHub

your-user/joind.in

local feature

joindin/joind.in

Page 30: Git, GitHub and Open Source

Sharing Changes

27

git push origin new-branch-name

GitHub

feature at origin

local feature

joindin/joind.in

push

Page 31: Git, GitHub and Open Source

Sharing Changes

28

To offer changes upstream, make a pull request

GitHub

feature at origin

local feature

joindin/joind.in

pull request

Page 32: Git, GitHub and Open Source

Making a Pull Request

29

Make the pull request on GitHub

Explain what you have changed, and why. Keep changes atomic.

Page 33: Git, GitHub and Open Source

Open Source Contributions

30

After that:

• Your pull request appears on the project’s list

• http://github.com/joindin/joind.in/pulls

• Hopefully it gets merged

• You get bragging rights :)

• https://github.com/joindin/joind.in/contributors

Page 34: Git, GitHub and Open Source

Where to Begin with Open Source

31

How to get involved: (warning, contains bias!)

• Check for introductory docs

• http://joind.in/about

Page 35: Git, GitHub and Open Source

Where to Begin with Open Source

31

How to get involved: (warning, contains bias!)

• Check for introductory docs

• http://joind.in/about

• Get code and set up the project

• usually, fork the repo and read the README

Page 36: Git, GitHub and Open Source

Where to Begin with Open Source

31

How to get involved: (warning, contains bias!)

• Check for introductory docs

• http://joind.in/about

• Get code and set up the project

• usually, fork the repo and read the README

• Find the bug tracker, and pick something

• http://joindin.jira.com

Page 37: Git, GitHub and Open Source

Where to Begin with Open Source

31

How to get involved: (warning, contains bias!)

• Check for introductory docs

• http://joind.in/about

• Get code and set up the project

• usually, fork the repo and read the README

• Find the bug tracker, and pick something

• http://joindin.jira.com

• Talk to the other people in the project

• #joind.in on freenode

Page 38: Git, GitHub and Open Source

Where to Begin with Open Source

31

How to get involved: (warning, contains bias!)

• Check for introductory docs

• http://joind.in/about

• Get code and set up the project

• usually, fork the repo and read the README

• Find the bug tracker, and pick something

• http://joindin.jira.com

• Talk to the other people in the project

• #joind.in on freenode

• Share and enjoy

Page 39: Git, GitHub and Open Source

Questions?

Page 40: Git, GitHub and Open Source

Thanks!

33

• Slides will be on slideshare

• Github: http://github.com/lornajane

• Twitter: @lornajane

• Web: http://lornajane.net

PHPNW - 3rd April, Derick Rethans on MongoDB. Rain Bar, Manchester.