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 • Project lead of joind.in, open source project

Slide 3

Slide 3 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 4

Slide 4 text

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

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

Distributed Version Control Or rather: repo repo repo repo repo

Slide 7

Slide 7 text

Code on GitHub

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

Fork the Project

Slide 10

Slide 10 text

Clone your Repo git clone [email protected]:username/joindin.git

Slide 11

Slide 11 text

Git: Many Repos GitHub your-user/joind.in development joindin/joind.in clone fork

Slide 12

Slide 12 text

Working with Git

Slide 13

Slide 13 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 14

Slide 14 text

Git Log Git automatically sends the output to a pager like less commit 76916fed387d9161d48b0f1e592685c183e4757c Author: Lorna Mitchell Date: Wed Mar 14 21:06:24 2012 +0000 adding the actual announcement wording to the banner commit 3fdc9f6b9795ed6a3a02465817bfebb8f77ca34e Author: Kim Rowan Date: Tue Mar 13 12:58:48 2012 +0000 Added info block to main page announcing php|arch Impact Award nom commit dc5777199aa2bb822b498ec1dea99f3e89ee90e0 Author: Lorna Mitchell Date: Sun Mar 11 21:03:13 2012 +0000 removed some unused files

Slide 15

Slide 15 text

Git Log There are some alternative views, this is git log -graph -oneline * 76916fe adding the actual announcement wording to the banner * 3fdc9f6 Added info block to main page announcing php|arch Impact Awa * dc57771 removed some unused files * aa502ec straightening out a problem with API metadata not showing up * 6719b8a GH #473: Refactored ternary to if * d6a69d7 Merge branch 'joindin-167' |\ | * b7effc5 JOINDIN-167: Facebook users without username (this is poss * | 6af9450 JOINDIN-167: reverted removal of facebook login * | 6249401 Merge branch 'master' of https://github.com/joindin/join |\ \ | |/ |/| | * 16b31d3 Merge remote-tracking branch 'lornajane/no-facebook' | |\ | | * 36ee9ea removing facebook login functionality - hopefully tempor | * | f4a2a73 removing references to the gravatar cache; these are ser | |/ | * 83d6c04 Prevented forwarding on to anywhere except this site after | * d411358 Merge remote-tracking branch 'mvriel/JOINDIN-161_2'

Slide 16

Slide 16 text

Git Status 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 ..." to update what will be committed) # (use "git checkout -- ..." to discard changes in working dir # # modified: src/.htaccess # modified: src/system/application/views/main/index.php # 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 monogit add

Slide 17

Slide 17 text

Git Add git add src/system/application/views/main/index.php git status again # On branch impact-banner # Changes to be committed: # (use "git reset HEAD ..." to unstage) # # modified: src/system/application/views/main/index.php # # Changes not staged for commit: # (use "git add ..." to update what will be committed) # (use "git checkout -- ..." to discard changes in working dir # # modified: src/.htaccess #

Slide 18

Slide 18 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 19

Slide 19 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 20

Slide 20 text

Managing the Multiple Repositories

Slide 21

Slide 21 text

Stay in Sync Pull the changes from upstream into your local repo GitHub your-user/joind.in development changes upstream pull git pull upstream master

Slide 22

Slide 22 text

Stay in Sync The changes are now in your local repo, push them to github: GitHub your-user/joind.in changes locally changes upstream push git push

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

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

Slide 25

Slide 25 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 26

Slide 26 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 27

Slide 27 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 28

Slide 28 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 29

Slide 29 text

Sharing Changes Your changes are in your local branch - how do they get into a main project? GitHub your-user/joind.in local feature joindin/joind.in

Slide 30

Slide 30 text

Sharing Changes git push origin new-branch-name GitHub feature at origin local feature joindin/joind.in push

Slide 31

Slide 31 text

Sharing Changes To offer changes upstream, make a pull request GitHub feature at origin local feature joindin/joind.in pull request

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

Open Source Contributions 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

Slide 34

Slide 34 text

Where to Begin with Open Source How to get involved: (warning, contains bias!) • Check for introductory docs • http://joind.in/about

Slide 35

Slide 35 text

Where to Begin with Open Source 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

Slide 36

Slide 36 text

Where to Begin with Open Source 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

Slide 37

Slide 37 text

Where to Begin with Open Source 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

Slide 38

Slide 38 text

Where to Begin with Open Source 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

Slide 39

Slide 39 text

Questions?

Slide 40

Slide 40 text

Thanks! • Slides will be available • Github: http://github.com/lornajane • Twitter: @lornajane • Web: http://lornajane.net • Feedback: https://joind.in/7554