Skip to main content

Working with Github

Written by: Akram Taghavi-Burris | Β© Copyright 2024

Status: In Development

GitHub is a widely-used version control platform, used for managing and collaboration on code and projects. It acts as a cloud-based version control tool, allowing developers and teams to track changes, collaborate, and share code securely. Whether you're working on software development, documentation, or any type of project, GitHub provides the tools needed to manage your work effectively.

GitHub Repository​

A GitHub repository is essentially the location where the code is stored. Think of it as a project folder, each project is its own repository or more commonly referred to as a repo.

GitHub Desktop​

While GitHub itself is cloud-based, you might want to access these repos locally on your computer. For this, GitHub Desktop is a handy tool that allows you to sync your cloud repositories with your local machine. This way, you can work offline when needed and easily manage your repositories from the comfort of your desktop. Whether you're cloning or Forking a repository, GitHub Desktop provides an intuitive interface to interact with your projects.

To access GitHub repositories

Using GitHub Classroom​

In an educational context, GitHub Classroom is specifically designed to enable educators to create assignments, sync (i.e. update) assignments, track student progress, and even auto-assign starter code. Using GitHub Classroom streamlines the assignment submission process while providing students with access to a collaborative environment that mirrors professional development work flows, making it an intuitive way for students to get started with version control.

πŸ›  Accept Assignment​

Tutorial: Github Classroom Assignment

πŸ“Version Control | πŸ•’5 minutes | πŸ“‚Required File: None

In this tutorial, we will go through the steps for accepting and accessing a GitHub assignment..

To begin using GitHub Classroom for your course assignments, you'll need to connect your GitHub account to the classroom set up by your instructor. Follow these steps to get started:


Step 1: Connect Your GitHub Account to the Classroom​

  1. Follow the Link Provided by Your Instructor
    Go to the link shared by your instructor (you can find it in the course LMS).

  2. Select Your Name from the List
    Once the page loads, find your name and select it from the list of students to connect your account.

    • If you accidentally select the wrong student name, contact your instructor to have the connection reset.

Join the Github Course

No Student List

If you don’t see a list of students to select from, simply accept the assignment by following the steps below. Accepting the assignment will automatically add you to the GitHub Classroom course.


Step 2: Accept Your Assignment​

Each assignment in GitHub Classroom will have its own repository that will automatically be created when you accept the assignment.

  1. Click the Link for the Assignment
    Use the link provided by your instructor to navigate to the assignment page.

  2. Accept the Assignment
    Click on Accept the assignment to join the course repository.

Accept the Assignment


Step 3: View Your Repository​

Once you've accepted the assignment, you will want to access repository (commonly referred to as a repo) page on Github.

  1. Refresh the acceptance page to see your repository.

To start working with your repository locally, you will need to copy the repo's web URL.

  1. Copy the Repository URL
    On the repository page, click the Code button. From the dropdown, copy the HTTPS URL of the repository.

Copy repo URL


πŸ›  Cloning a Repository​

Tutorial: Cloning a Repository

πŸ“Version Control | πŸ•’5 minutes | πŸ“‚Required File: None

In this tutorial we will go through the steps cloning a repository from GitHub using GitHub Desktop.

When working with GitHub, it's important to have a local copy of your repository to make changes, commit, and push updates. Cloning a repository allows you to work on it locally on your machine while syncing your changes with the cloud repository on GitHub.


Step 1: Open GitHub Desktop and Log In​

  1. Launch GitHub Desktop
    Open GitHub Desktop on your computer.

  2. Log In to Your Account
    Make sure you are logged in to your GitHub account in the desktop app.


Step 2: Clone the Repository​

  1. Navigate to Clone Repository
    In GitHub Desktop, go to the menu bar and click File > Clone Repository.

Clone Repo


Step 3: Select Your Repository​

  1. Choose from Your Repositories
    A new window will appear displaying all the repositories available in your GitHub account. Select the repository you want to clone locally.

Repo List


Step 4: Clone via URL (if needed)​

If you have a large number of repositories or if you are cloning a GitHub Classroom Assignment, you may want to use the URL option.

  1. Click the URL Tab
    In the dialog box, click the URL tab at the top.

  2. Paste the Git URL
    Paste the git URL you copied from the repository page on GitHub.

  3. Set the Clone Location
    Choose the folder where you want to save the repository on your local machine, then press Clone.

Repo URL


Step 5: Save Location​

Save Location

Ensure you select the correct location to save your local repository. For example, the repo should be saved to a folder like D:\Students\YourName.

Once cloned, you'll have a local copy of your repository and can begin making changes that sync with GitHub.

Using Github​

GitHub is not just for educational purposes; it's a powerful tool for personal and collaborative projects as well. By hosting your projects on GitHub, you can keep your work backed up and easily accessible from anywhere.

Additionally, GitHub serves as an excellent platform for building a professional portfolio. It is a the ideal platform to highlight not only your coding abilities but also your capacity for collaboration and problem-solving.

πŸ›  Remote Repository​

Tutorial: Creating a Remote Repo

πŸ“Version Control | πŸ•’5 minutes | πŸ“‚Required File: None

In this tutorial we will go through the steps for creating a GitHub repo remotely.

When you want to store your project remotely on GitHub, creating a remote repository is an essential first step. This allows you to share your work, collaborate with others, and back up your project in the cloud.


Step 1: Log In to GitHub​

  1. Open GitHub in your Web Browser
    Log in to your GitHub account in a web browser.

  2. Navigate to Your Profile and Repositories
    Go to your Profile page and click on Repositories to view your existing repositories.


Step 2: Create a New Repository​

  1. Click on the New Button
    Once you're in the Repositories section, click the New button to create a new repository.

New Repo


Step 3: Set Up Your Repository​

  1. Configure Repository Settings
    On the next page, set up your project repository by naming it, adding a description, and choosing any other settings like adding a README, .gitignore, or a license. Once you're ready, click Create Repository.

Repo Setup


Step 4: View Your Repository​

  1. View Your New Repository
    After creation, you’ll be redirected to the GitHub repository page. It should look similar to the screenshot below:

GitHub Repo

We have successfully created a remote repository for the project. To access this repository locally on your computer, follow the steps for Cloning a Repository.


πŸ›  Local Repository​

Tutorial: Creating a Local Repo

πŸ“Version Control | πŸ•’5 minutes | πŸ“‚Required File: None

In this tutorial we will go through the steps for creating a GitHub repo locally .

In the previous examples we have started our projects by creating a remote repository. However, you could start by creating a local repository directly from GitHub Desktop and then later sync it with a remote repository.


Step 1: Open GitHub Desktop​

  1. Navigate to New Repository
    Open GitHub Desktop, and go to File > New Repository.

Step 2: Set Up Your Local Repository​

  1. Configure Your Repository
    Just like when creating a remote repository, provide a name, description, and set any additional options such as README, .gitignore, or license.
    Ensure you specify the local path where the repository will be saved on your computer.

Local Repo Setup


Step 3: Save Your Local Repository​

  1. Create Your Local Repository
    After setting everything up, GitHub Desktop will create your local repository. However, this repository is not yet saved to the cloud.

To upload your changes to GitHub and sync it with the cloud repository, check the section on [Push, Pull, and Commits](#Tracking Changes).


Tracking Changes​

GitHub uses a version control system called Git to track changes in your project. The core actions in Git that interact with repositories are Commit, Push, Pull, and lesser mentioned Fetch. Understanding these actions will help you work effectively with GitHub and ensure your project is properly synced across different environments.

These behaviours can easily be defined as the following:

  • Commit: Record changes to your project locally.
  • Push: Send your local changes to the remote GitHub repository.
  • Pull: Retrieve the latest changes from the remote repository.
  • Fetch: Check for updates in the remote repository without merging them.

By regularly committing, pushing, pulling, and fetching, you'll maintain smooth version control and collaboration on GitHub.


Git Commits​

When working on a project using version control with Git, committing your changes regularly is crucial for several reasons:

  1. Track Your Progress: Committing frequently allows you to keep track of your progress over time. It provides a clear record of what has been done and when. If you need to revisit a previous state of the project or review a specific change, your commit history will provide a valuable reference.

  2. Easier Collaboration: When working with a team, frequent commits ensure that your changes are visible to others. This makes collaboration smoother, as others can pull the latest changes from the repository and integrate their work with yours without conflicts.

  3. Minimize Loss of Work: By committing regularly, you reduce the risk of losing valuable work due to unexpected issues such as crashes or accidental deletions. You can always go back to a previous commit and pick up from there.

  4. Better Debugging: Frequent commits allow you to isolate bugs more effectively. When a bug is introduced, you can easily pinpoint which commit caused the problem and roll back to a previous working state.

πŸ›  Commiting Changes​

Tutorial: Committing Changes

πŸ“Version Control | πŸ•’5 minutes | πŸ“‚Required File: None

In this tutorial we will go through the process of checking for changes and commiting thous changes.

Step 1: Check for Changes in GitHub Desktop​

After making edits to your local files, open GitHub Desktop to check for any changes since your last commit.

  1. Launch GitHub Desktop.
  2. You should see all the changes that have been made since your last commit.
Thousands of Changes

The .gitignore file is a special hidden file that tells GitHub which files to ignore when pushing or pulling repositories from the cloud. For Unity projects, the .gitignore file should be placed inside the Unity project folder and not the root folder of the repo. If you're seeing thousands of changes after adding a Unity project, ensure the .gitignore is properly placed to prevent unnecessary files (like local libraries) from being tracked.


Step 2: Commit Your Changes​

Once you've reviewed your changes, it's time to commit them to your local repository.

  1. Provide a brief description of your changes in the Commit message section.
  2. Click Commit to main (or the relevant branch).

Commit Changes

Committing will save your changes locally but won’t yet upload them to GitHub.

Naming Commits

Each commit needs a meaningful, descriptive name and while this might seem tedious at first, it's a best practice that makes your commit history much more readable and understandable to others (and your future self).

All commits require a title and optional description which should explain what was changed and why. It is best practice to use mean full titles and descriptions for better readability of the commits and avoids ambiguity such as with a commit titled Fixed stuff or Updated files.

Instead, use clear, concise messages like Fix button alignment on homepage or Add user authentication feature. For more examples see the sample commit naming scheme.


Step 3: Push Your Changes to GitHub​

Once you've committed your changes locally, you need to push them to your cloud repository.

  1. At the top of GitHub Desktop, click Push origin to send your local commits to GitHub.

Push Changes


πŸ›  Squash Commits​

Tutorial: Squash Commits

πŸ“Version Control | πŸ•’5 minutes | πŸ“‚Required File: None

In this tutorial we will go through the process of squashing multiple commits.

While it is important to provide meaningful titles and descriptions for your commits. Sometimes, after a long debugging session, you might find yourself committing multiple times at odd hours, with titles like:

  • IT FINALLY WORKS
  • I HAVE NO IDEA WHAT HAPPENED
  • Just... trying something!

While these can be a good way to let out some frustration 🀬, they are not helpful when reviewing commits and could be perceived the wrong way in a collaborative and professional setting.

In these cases, it’s a good idea to squash your commits, which essentially is the process combining multiple commits into a single commits with a more appropriate name before pushing them to the remote repository.


Step 1: View and Select Commits to Squash​

  1. Launch GitHub Desktop and navigate to the repository and choose the branch containing the commits you want to squash.
  2. Click the History tab in the left sidebar to see past commits.
  3. Hold Ctrl (Windows) or Cmd (Mac) and select the commits to squash.

Step 2: Squash and Edit Commit Message​

  1. Drag the selected commits onto the commit you want to merge them with.
  2. Modify the commit message to accurately summarize the changes.

Step 3: Finalize and Push​

  1. Click Squash Commits to combine them.
  2. Click Push origin to upload the cleaned-up commit history.

By squashing commits, you maintain a well-organized and meaningful history for your project. This not only helps others understand the progress but also makes it easier to track down specific changes later on.

Pull Requests​

A pull request (PR) is a way to propose changes to a repository and request feedback or approval before merging them into the main branch. It helps maintain a clear project history, ensures code quality, and allows for collaboration. For exercise submissions, a pull request allows your instructor to review your work before merging it.

πŸ›  Creating a PR​

Tutorial: Pull Request

πŸ“Version Control | πŸ•’5 minutes | πŸ“‚Required File: None

In this tutorial go over the steps for creating a pull request (PR).

Step 1: Open GitHub Desktop​

  1. Ensure you are on the branch you created for the exercise.
  2. Verify that all changes have been committed and pushed to GitHub.
  3. Click Preview Pull Request.

Preview PR


Step 2: Review Pull Request Details​

  1. A preview of the pull request will display, highlighting any conflicts with the main branch.
    • If no conflicts exist, proceed to the next step.
    • If conflicts exist, resolve them before continuing.
  2. Click Generate Pull Request.

Generate PR


Step 3: Open and Edit the Pull Request​

  1. The Open a Pull Request page will open in your browser.
  2. The title will default to your latest commit messageβ€”rename it to reflect the exercise name.
  3. Provide a brief description:
    • Summarize what changes were made.
    • Mention any questions or issues you encountered.

Open PR


Step 4: Set Assignee and Label​

  1. On the right side of the page:
    • Set Assignee to yourself.
    • Set the Label to Exercise.

Assignees to PR


Step 5: Create the Pull Request​

  1. Click Create Pull Request.
  2. The pull request will now be visible in the repository.

🚨 Do not click "Merge Pull Request." Your instructor will review and handle merging.

DO NOT Merge PR


Step 6: Instructor Review and Merge​

  1. Your instructor will receive a notification of the pull request.
  2. Once graded, your instructor will merge and close the pull request.

Merge PR


Broken Repos​

At times, GitHub Desktop may encounter an error when trying to push changes, such as indicating that the repository is not found or doesn't exist. This can happen for a number of reasons, including:

  • The repository may have been removed or is no longer linked correctly.
  • Network or connection issues between GitHub Desktop and GitHub.
  • Corrupt or incomplete local files causing syncing issues.
  • Incorrect configuration of the repository in GitHub Desktop or local directory.

πŸ›  Fix Out of Sync Repo​

Tutorial: Fix Out of Sync Repo

πŸ“Version Control | πŸ•’5 minutes | πŸ“‚Required File: None

In this tutorial we will go through the process fixing a repo that will no longer push to the cloud.

Occasionally you may encounter an instance where you have made several changes locally and when you try and push the changes back to the cloud you encounter an error that the repo no longer exists.

When this happens, the usual solution is to reset the local repository by removing it from GitHub Desktop and re-cloning it from GitHub. Below are the steps to resolve this issue and restore your changes.


Step 1: Backup Important Files​

  1. Navigate to Your Local Repository Folder
    Locate the folder where your GitHub repository is stored on your PC.

  2. Copy Important Files

  • Do not copy the entire repository folder.
  • Copy only the essential files and folders (e.g., your Unity project folder, scripts, assets, etc.).
  • Paste these into a separate location, such as your Desktop, for safekeeping.

Step 2: Remove the Repository in GitHub Desktop​

  1. Open GitHub Desktop.
  2. In the top menu, go to Repository > Remove....
  3. Select the repository that is causing issues.
  4. Click Remove (this will remove it from GitHub Desktop but not delete the local files).

Step 3: Re-Clone the Repository​

  1. In GitHub Desktop, click File > Clone Repository....
  2. Find the repository in the list or use the URL from GitHub.
  3. Select a location to clone the repository to (preferably the same directory as before).
  4. Click Clone and wait for the process to complete.

Step 4: Restore Your Updated Files​

  1. Open the folder where you cloned the repository.
  2. Copy only the necessary files and folders from the backup location (the ones you saved earlier).
  3. Paste them into the re-cloned repository folder, replacing the old files.

Step 5: Verify Git Ignore and Attributes Files​

  1. Make sure that .gitignore and .gitattributes are still present in the Unity project folder.
  • If you don’t see them, enable hidden files:
    • Windows: Open File Explorer > Click View > Check Hidden items.
    • Mac: Open Finder > Press Cmd + Shift + . to show hidden files.
  1. If .gitignore is missing, re-add a Unity-specific .gitignore file to avoid tracking unnecessary files.

Step 6: Commit and Push Changes​

  1. Open GitHub Desktop.
  2. You should see the restored files marked as changes.
  3. Click Commit to main (or the appropriate branch).
  4. Click Push Origin to upload your changes.

After passing your changes try accessing the repo online and ensuring that the fixed and synced correctly with GitHub.