Assignment Chef icon Assignment Chef
All English tutorials

Programming lesson

Mastering Git and GitHub for CSCI 340: A Step-by-Step Guide to Branching, Commits, and Pull Requests

Learn how to set up Git and GitHub for your CSCI 340 assignment, including SSH keys, branching, commits, and pull requests. Perfect for students new to version control.

CSCI 340 Git tutorial GitHub for students version control SSH key setup Git branching git commit git push pull request GitHub Classroom assignment submission coding workflow development branch open source contribution AI and Git app development workflow

Introduction to Git and GitHub for CSCI 340

Welcome to your first CSCI 340 assignment! This tutorial will walk you through the essential Git and GitHub skills you need to succeed. Whether you're a beginner or need a refresher, we'll cover everything from creating a GitHub account to submitting a pull request. By the end, you'll be comfortable with the version control workflow used in industry and open-source projects.

Why Git and GitHub Matter

Git is the most widely used version control system, and GitHub is the leading platform for hosting Git repositories. In your CSCI 340 course, you'll use Git to track changes, collaborate with peers, and submit assignments. Mastering these tools now will save you time and frustration later. Think of Git as a time machine for your code: you can experiment freely and revert if something breaks.

Step 1: Get a GitHub Account

If you don't already have a GitHub account, head to github.com and sign up. Choose a username that you'll use throughout your academic career. Your professor will use this username to identify your work. Once you have an account, you're ready for the next step.

Step 2: Accept the Assignment Invitation

Your professor will provide a GitHub Classroom invitation link. Click it and accept the assignment. This will create a personal repository (repo) for you on GitHub. The repo will contain starter code and a unique URL. Copy that URL – you'll need it to clone the repo to the university server (Turing or Hopper).

Step 3: Clone Your Repo to the Server

Log in to the NIU server (Turing or Hopper) and run the following command, replacing YOUR_REPO_URL_GOES_HERE with the URL from GitHub:

git clone YOUR_REPO_URL_GOES_HERE

This creates a local copy of the repo. Now you need to authenticate with GitHub. The recommended method is SSH key authentication. Let's set that up.

SSH Key Authentication (Recommended)

Generate an SSH key pair on the server using ssh-keygen. Press Enter to accept the default file location. Then display your public key with cat ~/.ssh/id_rsa.pub. Copy the output and add it to your GitHub account under Settings > SSH and GPG keys. Test the connection with ssh -T [email protected]. If successful, you can clone and push without entering a password.

Token Authentication (Alternative)

If you prefer not to use SSH, generate a personal access token on GitHub under Settings > Developer settings > Personal access tokens. Then, when Git prompts for a password, use the token instead. For convenience, you can cache the token using git config --global credential.helper cache.

Step 4: Create a Development Branch

Branches allow you to work on features without affecting the main codebase. For this assignment, you must create a branch called development. Do all your work on this branch.

cd YOUR_REPO_NAME
git branch development
git checkout development

Verify you're on the development branch with git branch. The asterisk should be next to development. Important: Committing to main or master will result in point deductions.

Step 5: Add Comments and Commit

The cloned repo contains a file assign1.cc with an intentional bug. For now, do not fix it. Instead, add a documentation comment at the top of the file with your name, section, Z-ID, and GitHub username. Follow the format exactly as specified in the assignment. After saving, stage the file and commit:

git add assign1.cc
git commit -m "Added documentation comment"

Your commit message should be descriptive. This commit will be separate from the bug fix commit.

Step 6: Fix the Broken Code

Run make to see the compilation error. Find the intentional bug (it's something simple like a missing semicolon or typo) and fix it. Then stage and commit again:

git add assign1.cc
git commit -m "Fixed compilation error"

Now you have two commits on the development branch.

Step 7: Push Your Commits to GitHub

Your local commits are only on the server. To make them visible on GitHub, push the development branch:

git push origin development

If this is your first push, you may need to set the upstream: git push -u origin development. After that, you can simply use git push.

Step 8: Create a Pull Request

Go to your repository on GitHub. You should see a banner suggesting you create a pull request for the development branch. Click it, or go to the Pull Requests tab and click New Pull Request. Set the base branch to main (or master) and the compare branch to development. Add a title and description summarizing your changes, then create the pull request. This signals to your grader that your assignment is complete.

Best Practices and Common Pitfalls

  • Always check your branch before committing. Use git status and git branch frequently.
  • Write clear commit messages that explain what changed and why.
  • Pull before you push if working in a team, but for individual assignments, this is less critical.
  • Don't delete the development branch after creating the pull request; the grader will merge it.

Connecting to Current Trends: Git in AI and App Development

Version control isn't just for school assignments. In the world of AI and app development, teams use Git to manage everything from machine learning models to mobile apps. For example, when building a viral app like a new social media platform, developers create branches for each feature (e.g., feature/user-authentication), commit changes, and merge via pull requests after code review. This workflow ensures stability and collaboration. Even in the gaming industry, studios use Git to track assets and code for games like Fortnite or Minecraft updates. By learning Git now, you're gaining a skill used by top tech companies like Google, Microsoft, and Netflix.

Conclusion

You've successfully set up Git and GitHub for your CSCI 340 assignment. You cloned a repo, created a branch, made commits, pushed changes, and opened a pull request. These steps form the foundation of modern software development. As you progress, you'll explore more advanced Git features like rebasing, stashing, and resolving merge conflicts. Keep practicing, and don't hesitate to refer to GitHub's documentation or ask your professor for help.