Working with Github
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β
-
Follow the Link Provided by Your Instructor
Go to the link shared by your instructor (you can find it in the course LMS). -
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.
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.
-
Click the Link for the Assignment
Use the link provided by your instructor to navigate to the assignment page. -
Accept the Assignment
Click on Accept the assignment to join the course repository.
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.
- 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.
- Copy the Repository URL
On the repository page, click the Code button. From the dropdown, copy the HTTPS URL of the repository.
π 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β
-
Launch GitHub Desktop
Open GitHub Desktop on your computer. -
Log In to Your Account
Make sure you are logged in to your GitHub account in the desktop app.
Step 2: Clone the Repositoryβ
- Navigate to Clone Repository
In GitHub Desktop, go to the menu bar and clickFile
>Clone Repository
.
Step 3: Select Your Repositoryβ
- 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.
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.
-
Click the
URL
Tab
In the dialog box, click the URL tab at the top. -
Paste the Git URL
Paste the git URL you copied from the repository page on GitHub. -
Set the Clone Location
Choose the folder where you want to save the repository on your local machine, then press Clone.
Step 5: 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β
-
Open GitHub in your Web Browser
Log in to your GitHub account in a web browser. -
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β
- Click on the
New
Button
Once you're in the Repositories section, click theNew
button to create a new repository.
Step 3: Set Up Your Repositoryβ
- 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, clickCreate Repository
.
Step 4: View Your Repositoryβ
- View Your New Repository
After creation, youβll be redirected to the GitHub repository page. It should look similar to the screenshot below:
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β
- Navigate to New Repository
Open GitHub Desktop, and go toFile
>New Repository
.
Step 2: Set Up Your Local Repositoryβ
- 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.
Step 3: Save Your Local Repositoryβ
- 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:
-
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.
-
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.
-
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.
-
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.
- Launch GitHub Desktop.
- You should see all the changes that have been made since your last commit.
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.
- Provide a brief description of your changes in the Commit message section.
- Click Commit to main (or the relevant branch).
Committing will save your changes locally but wonβt yet upload them to GitHub.
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.
- At the top of GitHub Desktop, click Push origin to send your local commits to GitHub.
π 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β
- Launch GitHub Desktop and navigate to the repository and choose the branch containing the commits you want to squash.
- Click the History tab in the left sidebar to see past commits.
- Hold Ctrl (Windows) or Cmd (Mac) and select the commits to squash.
Step 2: Squash and Edit Commit Messageβ
- Drag the selected commits onto the commit you want to merge them with.
- Modify the commit message to accurately summarize the changes.
Step 3: Finalize and Pushβ
- Click Squash Commits to combine them.
- 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β
- Ensure you are on the branch you created for the exercise.
- Verify that all changes have been committed and pushed to GitHub.
- Click Preview Pull Request.
Step 2: Review Pull Request Detailsβ
- 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.
- Click Generate Pull Request.
Step 3: Open and Edit the Pull Requestβ
- The Open a Pull Request page will open in your browser.
- The title will default to your latest commit messageβrename it to reflect the exercise name.
- Provide a brief description:
- Summarize what changes were made.
- Mention any questions or issues you encountered.
Step 4: Set Assignee and Labelβ
- On the right side of the page:
- Set Assignee to yourself.
- Set the Label to Exercise.
Step 5: Create the Pull Requestβ
- Click Create Pull Request.
- The pull request will now be visible in the repository.
π¨ Do not click "Merge Pull Request." Your instructor will review and handle merging.
Step 6: Instructor Review and Mergeβ
- Your instructor will receive a notification of the pull request.
- Once graded, your instructor will merge and close the pull request.
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β
-
Navigate to Your Local Repository Folder
Locate the folder where your GitHub repository is stored on your PC. -
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β
- Open GitHub Desktop.
- In the top menu, go to Repository > Remove....
- Select the repository that is causing issues.
- Click Remove (this will remove it from GitHub Desktop but not delete the local files).
Step 3: Re-Clone the Repositoryβ
- In GitHub Desktop, click File > Clone Repository....
- Find the repository in the list or use the URL from GitHub.
- Select a location to clone the repository to (preferably the same directory as before).
- Click Clone and wait for the process to complete.
Step 4: Restore Your Updated Filesβ
- Open the folder where you cloned the repository.
- Copy only the necessary files and folders from the backup location (the ones you saved earlier).
- Paste them into the re-cloned repository folder, replacing the old files.
Step 5: Verify Git Ignore and Attributes Filesβ
- 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.
- If
.gitignore
is missing, re-add a Unity-specific.gitignore
file to avoid tracking unnecessary files.
Step 6: Commit and Push Changesβ
- Open GitHub Desktop.
- You should see the restored files marked as changes.
- Click Commit to main (or the appropriate branch).
- 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.