Git in Github

Overview

Teaching: 30 min
Exercises: 15 min
Questions
  • How should we manipulate data?

Objectives
  • Define git vocabulary (commit, fork, pull request, repository, commit message).

  • Demonstrate ability to navigate through a GitHub repository main page.

  • Define the difference between a directory and a repository.

  • Create a repository on GitHub.

  • Demonstrate ability to commit changes to text files with a commit message.

  • Evaluate repository History.

  • Create a pull request to someone else’s repository.

Requirements

  • Must have a GitHub account.

Overview

  1. In this activity you are going to learn how to collaborate using GitHub. With a partner you will learn some basics which allow you to share and edit files on GitHub.
  2. Create a git repository hosted at GitHub
  3. Build README.md file
  4. Commit changes to repository
  5. Collaborate by forking and editing partners file
  6. Explore GitHub features: graphs, diff, blame, ect.

Step-by-Step

Create a repository with a README.md file

Follow along with your instructor and perform these steps:

  1. Go to your GitHub profile. The url should be http://github/your-user-name.
  2. Create a new GitHub repository, click the green “new” button, under the repositories tab.
  3. Name your repository work-organization-your-name
  4. In the details write “tips to organizing research”.
  5. Click the initiate a README.md file option.

So far

Edit the README.md file

tip: Notice that you can use markdown syntax. Use this guide for GitHub’s flavor of Markdown. Use the “Preview” button to view the formatting of your README.md file.

Commit

  1. Summarize the changes that you have made in 50 characters or less and click the green “commit button”.
  2. Check out the git history. You should now see two commits.

Edit and collaborate with your partner

Collaborate

Now it is time to collaborate with your partner. Navigate to your partner’s repository by typing the url directly into your address bar. In order to edit someone else’s repository you usually follow this simplified work flow:

  1. Fork their repository to your user account
  2. Make edits and commit
  3. Create a pull request that merges your changes into their repository.

tip: Depending on the project there are variations on the above work flow. Often the rules for contributing to a project are outlined in a file called CONTRIBUTING.md within the repository. One of the more often used works flows is GitHub Flow.

Forking

  1. To fork your partner’s repository click the “Fork” button in the top left hand part of your screen.
  2. When it asks where you would like to fork the repository, choose your user account (if you are new to GitHub, this should be the only option).

Make edits and commit

  1. Edit your partners repository by clicking the edit button.
  2. Paste in the answers to your questions under theirs and make a commit.

Create a pull request

  1. Make sure you are in your copy of your partner’s repository by looking at the url - your user name should preface the repository name.
  2. Click the green “New Pull Request” button. You will get an overview of the changes you made to the repository.
  3. Click the “Create a Pull Request” button to continue the pull request. Your partner will now get a notification of a pull request on their main repository, as will you if your partner made changes.
  4. Accept this pull request.

Explore GitHub features

Now that you have accepted the pull request. Take a few minutes to explore the git history using the “Graphs” section of the repository.

Extra Exercise after class:

Overview

RStudio and version controls

  • Git
  • Subversion

For this lesson we will focus on git

RStudio projects (required for version control):

Step-by-Step

  1. Fork the rr-version-control-demo repository.
  2. Clone your forked repository to obtain a local copy of the files into an RStudio project.
  3. Edit a file in this repository/project.
  4. Stage your changes to be committed.
  5. View the diff, and commit your changes, with a commit message.
  6. Push your changes to your own fork of the the rr-version-control-demo GitHub repository.

Step 1: Fork

Now you have a copy of rr-version-control-demo repository in your account, woohoo!

Aside - where am I?

How can I tell if I am looking at my fork or the original repository?

[your-github-name]/rr-version-control-demo

forked from Reproducible-Science-Curriculum/rr-version-control-demo

Step 2: Clone

Step 3: Edit

Step 4: Stage

Don’t worry about the other files that appear in this pane, we’ll get to them in a bit.

Step 5: Commit

Step 6: Push

push: When using git push always means pushing commits from your local respository (your computer) to a remote repository (GitHub).

Key Points

  • Keep raw data read only.

  • Manipulate data in a reproducible manner