0.3: GitHub

Learning Objectives

  1. GitHub is a code-hosting website that hosts Git repos for individuals or teams to review and collaborate on

  2. Know how to fork a repo on GitHub

  3. Know how to clone a repo from GitHub

  4. Know how to push changes to GitHub

  5. Know how to pull changes from GitHub

  6. Know how to view repo commit history in GitHub

Introduction

GitHub is a code-hosting website that hosts Git repos for individuals or teams to review and collaborate on. Team members can easily review latest code changes and commit history, making software development more transparent and thorough.

GitHub Workflow Summary

  1. Fork repos we do not have edit access to to suggest changes or maintain our own copy

  2. Clone repos to download local copies of GitHub repos

  3. Once we have committed the changes we want locally, push our changes to GitHub to share them with others. Refresh the GitHub repo page to see those changes.

  4. If we are working with teammates and wish to download their code while keeping local changes, pull their code from GitHub after committing our local changes.

GitHub Fork

A GitHub "fork" is a copy of another GitHub repo. SWEs typically "fork" repos they do not have edit access to either to make improvements to merge back into original repos, or to create and maintain independent versions of repos. At Rocket Academy we will fork Rocket exercise repos to complete and submit assignments.

We can fork a repo by clicking the Fork button on a GitHub repo page. Once forked, we can change our copy of the repo without affecting the original.

Git Clone

Once we have edit access to the repo we want to edit, either by forking an existing repo or creating a new repo, we can "clone" (i.e. download) that repo to our local machine to make changes to it.

Click the copy button in the Code dropdown menu on the GitHub page of the repo we wish to edit.

Then go to terminal, cd to the relevant folder and enter the command git clone <repo-url>, where <repo-url> is the URL we just copied from GitHub. This will create a new folder named after the repo with the repo's contents inside.

bootcamp % git clone https://github.com/kai-rocket/react.git
Cloning into 'react'...
remote: Enumerating objects: 203678, done.
remote: Total 203678 (delta 0), reused 0 (delta 0), pack-reused 203678
Receiving objects: 100% (203678/203678), 173.82 MiB | 5.85 MiB/s, done.
Resolving deltas: 100% (144768/144768), done.
bootcamp %

Once we've cloned the repo we can make edits to it and track our changes with Git.

Git Push

git push allows us to share local changes by "pushing" local commits to GitHub for others to view. Video demo below.

Git Pull

git pull allows us to download new changes in a shared GitHub repo (e.g. by teammates) while keeping our local changes. Git will automatically merge downloaded and local changes, and let us know if there are "merge conflicts", for example if downloaded and local changes edit the same lines of code. We will work more with git pull once we start group projects.

How to view commit history in GitHub

GitHub provides an easy way to view past changes to a repo. For example, if we are wondering which commit changed a line of code that caused a bug, we can easily find which commits changed that line, who made those commits and what other changes were in those commits.

Additional Resources

  1. (Below) Intro to GitHub video from prior version of Rocket's Coding Basics course

  2. (Below) GitHub Fork video from prior version of Rocket's Coding Basics course

  3. (Below) GitHub Repo Browsing video from prior version of Rocket's Coding Basics course

In the below GitHub Fork video we demonstrate git push origin master, but for most purposes git push will suffice.

Last updated