Try   HackMD

CS 410 Github Overview

What is GitHub?

GitHub is an interface built on Git, a version control system you can use right from the command line. GitHub allows you to store code and make changes to an online repository. This enables you to easily update your code as well as collaborate with others by sharing a common repository. We will be using GitHub Classroom to distribute all of the stencil code for assignments, which you can access from the course website. Let’s learn a little more about GitHub and Git!

Why GitHub?

  • Store your code and files on an online repository so you won’t lose your code.
  • You can commit (save) and push your code often so:
    • If your computer crashes or you make a mistake, you can revert to an earlier version of your code and keep working.
    • You can create a record of changes and always check out a previous version.
  • Easy collaboration: people can work on the same repository and update/change code on separate machines.

You can sign up for an account here and get the GitHub Student Pack with your Brown email for more tools and features.

Some Essential Git Commands

Below are some common Git commands to get you started!

  • git clone [URL-or-path-to-repo] - Retrieve an entire repository from a hosted location via URL to your local machine
  • git status - Display the state of the current repository. Use this to see your tracked files, untracked files and changes.
  • git add [file] - Add the given file to the repository. Use this when you create a new file and want to include it in a commit. Alternatively, include [-a] to add all files from your local repo
  • git commit -m [some message] - Commit your code to finalize and save changes to your current branch and repo on your local machine.
    Include [-a] to automatically add changed files that git is already tracking and [-m “[some message]”] to include a message about the commit (otherwise you will be kicked to an editor in which to type out your message).
  • git push - Push whatever commits you have made locally to the repository you cloned from to save your changes to the online repo. (You might have to pull first to sync with the remote repository)
  • git pull - Pull any changes from the remote repository you cloned from.

Github Desktop

If you prefer GUIs we recommend using GitHub Desktop, this gives you a great visual way of interacting with GitHub. It allows you to better visualize your code changes when you commit and push, and helps prevent committing files that you don't want to be stored in your repo.

You can download Github Desktop for your platform here, and follow the setup guide here.

GitHub Classroom

You will use GitHub Classroom in this course. All assignments and stencil code will be available through an assignment link on the webpage. Once you click on the link this is what you should see:

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

After clicking the button, GitHub will create a repository unique to you and after everything loads, you should see this page:

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

After clicking on the link, it will navigate you directly to your own private repository with the stencil code already in the repository.

Downloading a Repository

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

Now you have your own personal repository for the project! You can preview the files on this webpage, but in order to change them and actually work on the assignment, you should download them to your computer using the following instructions.

Click on the Code button and you will see:

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

To download the files to your computer, you have 2 options:

  1. Copying the URL and use the Git command git clone [URL]. Follow these steps:
    • Copy the HTTPS URL
    • In your terminal, navigate to a directory where you want to save the project and then run: git clone [URL]
  2. OR select “Open with GitHub Desktop.” To use this option, you must download the desktop app (see the section above called Github Desktop).
    • Click on “Open in Desktop”. This will take you to the desktop app and show a page like:
      Image Not Showing Possible Reasons
      • The image was uploaded to a note which you don't have access to
      • The note which the image was originally uploaded to has been deleted
      Learn More →
    • Once you specify the file path you want the repository to be and click clone, everything should download to that folder! You can now open the folder in your favorite text editor and start coding!

Editing and Committing Changes

Now that you have a folder with the template code on your personal machine, you can edit those files. Once you're ready to save or backup your changes, you can follow these steps:

  1. Open a terminal and cd into the project directory.
  2. Add all the files to your working branch by running the command git add --a
    • Alternatively, if you only want to save a particular file to, you can run the command
      git add [PATH_TO_FILE]
  3. Make a short description of the changes that you've made by running git commit --m "[SOME_MESSAGE]"
  4. Push the changes to GitHub by running git push

Remember to commit often to save a record of your code and push to the remote repository to save it on GitHub as well.

Note: You may need to create a GitHub Personal Access Token to clone using the command-line interface.