Getting git-ting like a champ

Andee Kaplan

Get git-ting!

Slides are available at http://bit.ly/git-ladies

Today’s Goal: Getting git-ting like a champ with your fellow

-ladies.

What is git? Why do we want it?

http://xkcd.com/1597/

Definition/background

Note: Thanks to http://happygitwithr.com for inspiration and material. There is so much more here, so check it out.

Terminology

Terminology (Cont’d)

From https://help.github.com/articles/github-glossary/

GitHub

There are many hosting services for remote repositories (GitHub, Bitbucket, GitLab, etc.). We will use GitHub in this class, but the ideas carry over to the other services.

By default, all materials on GitHub are public. This is good because you are getting your work out there and contributing to the open source community!

If you need private repos, checkout GitHub for Education - free private repos for students/postdocs/professors.

Doing stuff

Creating Repos

Initialize readme (yes), .gitignore (R usually), license (e.g. GPL 3)

Your Turn

  1. Create a GitHub account
    • github.com
    • Consider your username, want to be identifiable, professional and probably include your actual name. Do you have other handles? Twitter?
    • Don’t worry about paying for a plan now, stick with the free one.
  2. Create a hello-world repo

Creating Repos (Cont’d)

From scratch
  1. Create the repo on the GitHub website
  2. Clone the repo
  3. Start working
  4. Add files, commit, push, etc.

From existing folder
  1. Create the repo on the GitHub website
  2. Clone the repo
  3. Copy existing work into local folder
  4. Add files, commit, push, etc.

Pushing and pulling, a tug of war

Important: remember to pull before you start working to get the most up to date changes from your collaborators (or your past self) before making local changes!

SourceTree

Your Turn

  1. Install a client
  2. Clone your hello-world repo

When should I commit?

Think of commits as a checkpoint in a video game. This is a point in time when you want to save your status so that you can come back to it later if need be.

Commits are like voting. I like to do it early and often.

- Me, right now

Blow it up

Sometimes your local repo gets borked. That’s OK. There are ways that we can work really hard and fix them, but sometimes you just want to stash your files somewhere and re-clone from your centralized repository.

Conflicts

Git’s ability to resolve conflicts is very useful, but conflict resolution costs time and effort, and can introduce errors if conflicts are not resolved correctly.

Your Turn

  1. Edit the README file in your hello-world repo
  2. Commit and push changes
  3. Check out your commit history!

Collaboration

(Cy-)Cloning a repo

If you want a copy of somebody’s repository and you also want to track its evolution then you should clone it. This allows you to pull from the remote, but will not allow you to push (unless you are a collaborator).

This is different from downloading a zip of a repo because you can keep your local version up to date with the remote.

Forking A (repo)

If you think you will want to propose a change to a repository, then you should fork it instead of cloning it.

This creates a copy of the original repo in your GitHub profile. You can now clone your own fork and make changes as usual (pull, commit, push) to your fork.

Acheiving that PR

No, not personal record… pull request!

When you are ready to propose a change to the origin of your fork, place a pull request from your fork to the original repo owned by someone else.

Git-ladies to Git-R-ladies

Many of your favorite R packages are developed on GitHub!

Meaning you can contribute!

Your Turn

  1. Fork the repo from https://github.com/andeek/helloLadies
  2. Edit the repo in some way.
    • Ideas: Edit the readme, add a new R function, add some documentation, find a bug, go nuts!
  3. Create a pull request with your changes.

More help

We have not covered possible installation issue in this workshop If you would like to work through it on your own, here is an excellent guide: http://happygitwithr.com/installation-pain.html

More in-depth tutorials: