Assignment
Purpose: To gain experience collaborating using github.com.
I created a repository on my CrumpLab account called 7709Rproblems. The link to the repository is:
https://github.com/CrumpLab/7709Rproblems
This repository contains two .rmd files. One for the fizzbuzz problem, and one for the snakes and ladders problem. The goal of this assignment is for the class to contribute their solutions for each problem to these documents. Along the way you learn about using github for collaboration.
Outline of steps
- Login to you github account
- go to https://github.com/CrumpLab/7709Rproblems
- Fork this repo to your github account using the little fork button (top-right)
- Open github desktop, click add, choose clone, then clone the 7709Rproblems repo to your computer
- Open the new repository on your computer, and then open the .Rproj file to load this as a new R-studio project
- Edit the fizzbuzz.Rmd file to include your name and the code you wrote to solve this problem. Then knit the file.
- Edit the snakesladders.Rmd file and do the same
- If you don’t yet have working code that’s ok, make a spot with your name, and leave comment that say’s working on it.
- Commit your changes using github desktop, then push the changes to your github account
- Go to your github account, go to your copy of 7709Rproblems and submit a pull-request (see video)
- That’s it!
Github can be complicated and confusing. Below are some notes about creating Github repositories that might be helpful as reference.
Tips
This tutorial has two goals.
To allow our class to create a database of coding solutions for a few of the harder problems. For example, after each student has completed the fizzbuzz problem, they will use the process described here to upload their code to a github repository. The repository will contain multiple solutions for each problem. This can be used as a resource for students to view and learn about different ways to solve the coding problems.
- To become competent in basic github operations, including:
- Creating a new repository on the github website
- Cloning the repository to your local computer
- Making changes to the repository
- Uploading the changes (pushing changes)
- Cloning a repository from someones existing repository to your local computer
- making changes to the cloned repository
- making a pull request to the owner of the cloned repository, so that your new additions are included.
Github Repo basics
How to create a new repository on Github.com
Create the repository on the website first, then clone it to your local computer using github desktop
Step 1: Create a repository on Github
- Go to your github account, and find your list of repositories. One way to do this is to login, then click on your user icon (top right). You should see a list of options, choose “Your repositories”.
- Click the green “New” button
- Give your repository a name
- Give your repository a brief description
- Choose public
- Click the option to “Initialize this repository with a readme”
- You have now created a new repository that is on the cloud. You should be able to see this repository listed in your list of repositories. This is basically a file folder on the cloud that contains a single file in it, the readme file. The contents of the readme file are always displays below the list of files in the repository. This is useful for visitors who can read your a description of the purpose/contents of the repository
Step 2: Clone the repository to your local computer
- Open github desktop, make sure your user account information is correct so that github desktop logs in to your github account
- It can take some time to get used to what you are seeing when you open github desktop. You may be “inside” one of your repositories, or you may be looking at a list of repositories. Go to the list of your current repositories: choose “view” from the menu, and choose “Repository List”.
- You should see the option to “add” appear as a button in the top left. Click “add”
- Choose the “Clone repository…” option
- You should now see a list of repositories that are on the Github.com website. Included in this list should be the name of the new repository that you just made on the Github website. Select the new repository
- You will be making a copy of the github repository in a new folder on your computer. You have to choose where you will save this file on your computer.
- BE CAREFUL: I recommend that you have folder on your computer for storing github repositories. For example, on my computer I have a folder called “Repos”. Whenever I clone a repository from github, I put that repository in the “Repos” folder. That way I know where all of my cloned repositories are on my local computer.
- It is not a good idea to put a github repository inside another github repository. For example, you already have a cloned github repository for your website code. Do not put a new repository inside this folder.
- After you have set the path where you will save your repository, click clone
- You should now have a cloned copy of the github repository on your local computer
Make a new repository on your local computer, then publish it on github.com
This is another way to create a github.com repository that is connected to a local copy. There is no need to first create a new repository on github.com
- Open github desktop
- View repository list
- Choose add “Create New Repository”
- Give it a name
- Choose where to store the new repository on your computer
- choose initialize with readme
- choose “create repository”
- You now have a new git folder on your computer
- If you want to “publish” to github.com, then choose the publish option that appears in the right-hand side of github desktop.
- unclick “keep this code private” (for this course)
- click “pubish repository”
- After publishing you should see a new repository appear on github.com. Any changes you make to your local copy can now be pushed to the github.com copy.
Making changes to a cloned folder
Whenever you add files to your cloned folder on your computer, or whenever you make changes to existing files in that folder, those new changes will be logged in github desktop.
- You can test this by opening the readme file and making an edit, then saving the document. To verify that github is recording the changes do the following:
- Open github desktop
- Make sure you are “inside” the relevant repository. If you are not already there, go to the list of repositories, then click on the one you want to look at
- When you have opened the repository, you will see the name of your repository appear in the top left drop down “current repository”.
- You should see a count of the number of changes that have been made
Pushing changes to github.com
tip: this is a two stage process: commit, then push
- If you have made changes, the first step is to “commit” them. The option to commit is in the bottom left corner. Give a brief description of the changes (this description is saved as a note for your reference, and giving a description is required). Press commit.
- Note: At the commit stage your changes are still on your local computer, they have not been sent to the cloud.
- After you have committed the changes, then press the “push” button on the right-hand side. You have now pushed your changes to the github.com repository (you must be connected to the internet to do this)
- You can verify that the push worked by going to your repository on github.com. You should be able to see the changes in your files there.
Common issues
It is easy to run into problems when creating and using github repositories. For example, you might have created a repository in github desktop that you think is linked to github.com, but then you found it is not linked. The following is an attempt to help you understand basic github ideas so you can identify the problem you may be having. We will focus mainly on different kinds of repositories, and their locations.
The first two repository types are github.com repositories, and cloned local copies of github.com repositories. These are the two kinds of repositories we will be using in this course. You will run into issues if you are not using these two kinds of repositories.
- A Github.com repository. You create these on github.com in your github account using the new repository button.
- Where is it? On github.com
- Is it on my computer? No
- Can it be cloned to my computer? Yes, and when you do this, you know have two repositories. One on github.com, and a local version that is connected to the one on github.com (you can push changes from your local copy to github.com using github desktop)
- A cloned repository from github.com on your local computer. You create the clone from github.com using the process described above.
- Where is it? on your computer
- Is it on my computer? yes
- Is this copy connected to github.com? It should be if you followed the above steps using github desktop to make the clone.
When you set-up a cloned copy of a github.com repository on your local computer you are making a two-way street between the folders, allowing changes to be sent back and forth. If you make a change to the files on your local computer (and as a result they become different from the files on github.com) then you can push those changes to github.com so that both folders become “equal”. It is also possible to edit files on github.com. If you make a change to a file on github.com, then the files there will be “ahead of” or different from the files on your local clone. In github desktop you can “fetch origin”, and then “pull” the changes from github.com into your clone. This will also make the two folders equal again (e.g., all files the same).
Other kinds of git repositories
Github desktop is a program that allows you to link up github.com repositories with local copies (clones) on your computer, and pass changes between them. It also allows you to create git repositories on your local computer that are not linked up with github.com repositories. If you accidentally create one of these local repositories, then it will not allow you to send changes back and forth between a github.com repository.
- “Create new repository”: You will see that github desktop gives you an option to “create new repository” when clicking the add button. This creates a new git repository on your local computer.
- Where is it? on your computer
- Is this copy connected to github.com? No
- What kind of folder is this? This is a git folder. It has similar functionality to clones from github.com, but it is not connected to any repository on github.com. It is just a local folder with version control. If you make changes to files in this folder, the changes will be tracked. You can still commit changes. But they won’t be pushed to github.com, because this folder only exists on your local computer.
- Example problem You choose “create new repository” and give it the same name as a repository that exists on your github.com account. The new repository will be created on your local computer, but it will not be connected to the one on github.com. Follow the earlier steps about cloning a github.com repo to your local computer to connect your local repo to the github.com repo.
- Is it possible to connect this repository to github.com Yes, you can use the publish repository option in github desktop.
- “Add existing repository” is another option that github desktop gives you. This option allows you to bring in a git folder that you may have on your computer, and allow it to be managed by the github desktop program. When you do this, github desktop will begin tracking the changes in the git folder that you added.
- Where is it? on your computer
- Is this copy connected to github.com? No
Example problem 1. You notice that you can download an entire repository from github.com using the download .zip button, then you download the repository to your local computer, and unzip the repository. Now you have the files copied to your computer 2. You use github desktop to add this folder as a repository. 3. If the adding works, the new local copy will not be connected to github.com 4. If you did this, you might have problems trying to use the clone option. 5. Solution: Delete the repository that you just added to github desktop (e.g., delete it from github desktop). Then try cloning from github.com using previous instructions.