git & github

ben best | ucsb data science

2015-07-16 | bbest.github.io/ds-git

introduction

outline

  1. introduction
    • why bother?
    • workflow
    • fork & pull model
    • github features
  2. exercises
    1. hello world
      • http://github.com/[user]/hello-world
    2. create a website repo
      • http://[user].github.io
    3. fork & pull a repo
      • stevejbrown/rss_article_recommender

why bother?

example workflow

  1. sign up at github.com (1x/user)
  2. install git (1x/machine)
  3. create [or fork] a repository, aka "repo" (1x/repo)
  4. clone from web to your local desktop (1x/repo)
  5. [branch copy for isolated development of a feature (1x/feature)]
  6. commit changes locally
  7. push changes to your repo
  8. [pull request changes from your repo to source repo that was forked)]

models of development

fork & pull model

github.com/[user0]/[repo]
(orig, web)
github.com/[user]/[repo]
(you, web)
~/github/[repo]
(you, local)
(1x) fork clone
commit
branch
push
merge pull request

where:

github features

github rendering: text

Track Changes view with "Rendered" button to view differences between versions of a text file: additions in green, removals in red strikethrough. Details: Rendering differences in prose documents

Source

Source

Rendered

Rendered

github rendering: images

Image view show differences in 3 ways: 2-up, swipe and onion skin views. Details: Rendering and diffing images

Onion Skin

Onion Skin

github rendering: csv

CSV view allow for on the fly tabular view, searching for text, and linking to specific rows of data. Details: Rendering CSV and TSV data.

select rows, URL to select

select rows, URL to select

search

search

github rendering: geo

Geographic view of GeoJSON or topojson files render automatically as a map. Details: Mapping geoJSON files on GitHub

interactive map with zoom, click on details, OpenStreetMap

exercises

ex 1: hello world

Create a hello-world repository and tour some of Github's most useful features. You only need a web browser and Github account (no git or other desktop software required).

  1. Sign up for a new GitHub account

  2. Follow the GitHub Guide Hello World to walk through essentials of: repositories, branches, commits, issues and pull requests.

ex 2: create a website repo

Create a website repository in Github. You only need a web browser and Github account (no git or other desktop software required).

  1. Create repo [user].github.io, where [user] is your github username
  2. Create pages
    • Have fun picking a theme!

ex 3: fork & pull a repo

Fork the repo stevejbrown/rss_article_recommender.

  1. Set up git if you haven't already
    • git + github applications recommended
  2. Fork the repo
    1. Fork this repository: https://github.com/stevejbrown/rss_article_recommender
    2. Clone your forked repo to your desktop

      mkdir ~/github
      cd ~/github
      git clone https://github.com/[user]/rss_article_recommender.git
      cd rss_article_recommender
    3. Edit files. For the sake of testing, create a new file [user].txt where [user] is your Github username. We'll start with each of us editing different files so as to avoid merge conflicts.
    4. Commit changes and push

extra

md to html slideshow

This presentation was created in markdown (see index.md) and rendered as an HTML slideshow with pandoc. Details: Producing slide shows with Pandoc. To render the HTML, the content was placed in the gh-pages branch of the ds-git repo.

Here's some code to get the idea:

# clone "ds-git" repository made on github.com to local machine
cd ~/github
git clone https://github.com/bbest/ds-git.git

# create new "gh-pages" branch
cd ds-git
git checkout -b gh-pages

# create document index.md in editor like http://atom.io

# convert from markdown (*.md) to html slidy with options
pandoc \
  -t slidy \
  --self-contained --incremental --slide-level=2 \
  --css=octicons/octicons.css \
  index.md \
  -o index.html

# check status, note untracked files
git status

# add files for git tracking, and commit changes locally
git add *
git commit -a -m 'initial presentation'

# push to remote, set upstream (1x)
git push -u origin gh-pages

# push (after 1x)
git push

To see all the pandoc options:

pandoc --help

Also set the default branch to gh-pages, since master not otherwise being used.

further resources