Slide 1

Slide 1 text

Git, GitHub and Open Source Lorna Mitchell, NW DrupalCamp 2013

Slide 2

Slide 2 text

GitHub "We make it easier to collaborate with others and share your projects with the universe" • GitHub is hosted source control, based on git • Used for many open source projects, also good for your own projects • Competing alternatives exist

Slide 3

Slide 3 text

How to Get Code from GitHub

Slide 4

Slide 4 text

Find and Fork First, find the project and fork it

Slide 5

Slide 5 text

Why Fork? • To have your own copy • To allow you to share changes without having write access • It is possible to clone a read-only repository

Slide 6

Slide 6 text

Clone the Repo Get the URL you need (https recommended)

Slide 7

Slide 7 text

Clone the Repo Clone it

Slide 8

Slide 8 text

Examining Changes with Git

Slide 9

Slide 9 text

Git Log This goes to a pager; press 'q' to exit

Slide 10

Slide 10 text

Git Log My favourite switches: git log --oneline --graph --decorate

Slide 11

Slide 11 text

Stay in Sync

Slide 12

Slide 12 text

Git Remotes Your local repo has remotes • origin is created by default and points to where you cloned from • upstream is usually the main project repo • Add as many remotes as there are collaboration points To view remotes: git remote -v

Slide 13

Slide 13 text

Remote and Local Repos

Slide 14

Slide 14 text

Get Upstream Changes git pull upstream master

Slide 15

Slide 15 text

Get Upstream Changes

Slide 16

Slide 16 text

Update Your Fork Push changes from your local fork to your GitHub origin: git push This defaults to origin but you can also specify which branch to push and to where: git push upstream develop

Slide 17

Slide 17 text

Update Your Fork

Slide 18

Slide 18 text

Git and Branching Branching is quick, easy and efficient. More importantly, so is merging! Your repo will switch itself to a different branch when asked

Slide 19

Slide 19 text

Git Branching Strategies Each project will have its own branching strategy. You may need to: • branch per feature • branch per ticket (with appropriately-named branches) • branch per version

Slide 20

Slide 20 text

Make a Branch New branch called experiment: git checkout -b experiment Push the contents of that branch to your GitHub origin: git push origin experiment Change to an existing branch: git checkout otherCoolFeature

Slide 21

Slide 21 text

Make and Share Changes

Slide 22

Slide 22 text

Making Changes in Git Changes can be in one of three states

Slide 23

Slide 23 text

Git Status Shows various sets of changes • Changes staged for commit • Modified files • Untracked files • (Unmodified tracked files aren't shown)

Slide 24

Slide 24 text

Make Changes When a file has been changed, run git status

Slide 25

Slide 25 text

Git Diff See changes in the working area: git diff See changes staged for commit: git diff --staged

Slide 26

Slide 26 text

Prepare Changes Use git add README.md to add the file

Slide 27

Slide 27 text

Some Notes on Committing • One feature, many atomic commits, one branch • Meaningful commit messages • Layout/coding standard fixes should be separate • Git encourages careful preparation of commits

Slide 28

Slide 28 text

Commit and Share Complete the changeset by committing git commit -m "Excellent message here"

Slide 29

Slide 29 text

Commit and Share

Slide 30

Slide 30 text

Commit and Share

Slide 31

Slide 31 text

Your Changes on GitHub Since we pushed to GitHub, we can see the changes there:

Slide 32

Slide 32 text

Pull Requests Literally request someone does a pull from your repo! They provide: • an easy way to see offered changes • a great interface for reviewing changes • tools for discussion of changes

Slide 33

Slide 33 text

Open a Pull Request Go to the new branch you pushed

Slide 34

Slide 34 text

Open a Pull Request Check the diff and add a summary

Slide 35

Slide 35 text

Open a Pull Request

Slide 36

Slide 36 text

Open a Pull Request You'll get an email when it is updated

Slide 37

Slide 37 text

Contributing to Open Source

Slide 38

Slide 38 text

When to Contribute When you can improve a project Even a teeny tiny bit

Slide 39

Slide 39 text

Why to Contribute To help To improve your own skills As an excellent hobby

Slide 40

Slide 40 text

How to Contribute Projects will publish some information for you • Contributor guidelines • Contact mechanisms • Issue lists http://joind.in/about

Slide 41

Slide 41 text

Questions?

Slide 42

Slide 42 text

Thanks Feedback please! Lorna Mitchell, consultant, author, developer and trainer, available for interesting projects • http://github.com/lornajane • @lornajane • http://lornajane.net