Skip to content

Instantly share code, notes, and snippets.

@pathawks
Last active October 16, 2015 17:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save pathawks/6186aa02d1ba44658f9c to your computer and use it in GitHub Desktop.
Save pathawks/6186aa02d1ba44658f9c to your computer and use it in GitHub Desktop.
Getting Started with GitHub

How cool is GitHub?

  • Sharing code, no email
  • Work with better programmers
  • Get noticed

Gist

  • Use GitHub without using GitHub

What is source control?

Alice and Bob are working together on a project.
They each have a copy of the project on their computers.

  • Alice makes a couple changes to her copy
  • Bob makes a change to his copy

How will these changes come together?

Git allows different people to work on a project separately and then, some time later, bring all of the changes together.

Why use source control?

  • Made a bad change and need to revert back to a known good state
  • Want to see diff between versions
  • Want to see how long a bug has existed
  • Experiment without breaking working code

Tracking changes is what Git does

Git Structure

.git folder

  • Stores changes
    • hashes, diffs, text
  • Delete it, no more git
  • Universal Git API

Distributed

Start on local machine, push to GitHub when you need to collaborate

Repository

  • Think of it like a project
  • Limited in scope

Git Commits

Snapshot

Can look at differences

  • Contain:
    • Commit ref
      • 40 characters
      • UUID
    • Author name / email
    • Commiter name / email
    • Date & time
    • Message
  • Each commit should tell a coherent story
  • Commit messages are important
  • Each commit should have a message explaining
  • One file at a time, or multiple related files at once

![Merge branch 'asdfasjkfdlas/alkdjf' into sdkjfls-final] (http://imgs.xkcd.com/comics/git_commit.png)

History

  • Can roll back to a specific point in time later
  • Can see when a change was introduced

Branches

  • Start work on new branch
  • MASTER should be production

Installing Git

Many options

  • Eclipse plugin
  • GitHub for Desktop
    • Compromise between ease of web interface and power of command line

Features of GitHub

  • Hosted Repositories
    • Can be public or private
    • Students can have up to five free private repos
    • Can have one contributor, or many contributors
    • Built in Issue Tracker
      • Issues =/= Bad
      • @mentions
      • Anyone can comment on an issue
      • Subscribe button
      • Notifications
      • Closed issues are saved in history forever
      • Pull Request is a special kind of issue
  • Can edit files (and commit changes) directly in the web interface

GitHub Collaboration

  • Fork
    • Create your own copy
    • Do whatever you like
    • Changeset container
    • Forks are good!
  • Pull Request
    • Special kind of issue with changes attached
    • After you have made useful changes
    • Offer your changes back to the origin

![There are probably children out there holding down spacebar to stay warm in the winter! YOUR UPDATE MURDERS CHILDREN.] (http://imgs.xkcd.com/comics/workflow.png)

GitHub Pages

  • Every Repo has it's own website
  • gh-pages branch
  • Users can have their own static website hosted by GitHub
    • <username>.github.com

Getting Started with GitHub

  • Create an account
  • Fill out profile
  • Test Repo
    • Initialize with Readme
    • Edit Readme
    • Look ma, no downloads!

Bringing it all together

  • Find a repository you'd like to contribute to
  • Read project's Contributing.txt to learn how to be a good citizen
  • Fork project repo to create your own copy
  • Create a new branch in your fork that will hold the changes for this feature
  • Commit your changes to this branch to add a feature or fix a bug
  • Submit a Pull Request to announce your changes, offering them back to the origin
    • In the message of the Pull Request, be sure to explain exactly what your changes do
    • This will usually spark a conversation around the Pull Request
    • You may be asked to add something to your pull request
    • Just push more commits to your branch
    • Once pull request has been accepted/rejected, you may delete your branch
    • Probably a good idea not to delete your Fork, however
  • ...profit?

Gist Revisited

  • Each Gist is actually a Git repo
  • Keeps a full revision history
  • Can be cloned & forked
  • Can be "upgraded" to a GitHub repository later

Git Bits

.gitignore

  • Ignore generated files
    • .exe
    • .class
    • .o
    • Config files
  • Ignore large files that can be found elsewhere
    • ENABL

HEAD, master, detached head

Configure command line client

git diff

Image attribution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment