git50

Git50 - Submitting CS50 Assignments with Git

Disclaimer: This guide is unofficial. While this guide is meant to help with submitting CS50 assignments, it is not maintained by CS50 staff.

Already have git installed and set up? Skip to Submit Your CS50 Assignment.

Installing Git

If you don’t have git installed, get the download for your operating system from https://git-scm.com/downloads.

Once the install has finished, you may need to restart VSCode before you can use it.

Run this command to make sure it is installed correctly:

git --version

You should see something like the following, depending on your operating system and the version of git you installed:

git version 2.37.1.windows.1

Setting Up Git

Once you have git installed on your machine, you need to tell git who you are. If you try to make a commit without doing this, it will fail and ask you to set up this config.

This setup only needs to be done once after installing git.

Use the following commands to set up your display name and your email. This name and email will be attached to any commits you make.

git config --global user.name "YOUR NAME HERE"
git config --global user.email "YOUR EMAIL HERE"

(OPTIONAL) Keeping Your Email Address Private

Because the email in your git config is attached to any commits you make, you might not want to use your email here if you’ll be commiting to any public repos on GitHub.

If you’d like to keep your email address private, follow these steps to get a noreply email address from GitHub:

  1. Go to your GitHub email settings
  2. Check the box that says Keep my email addresses private
  3. Copy the @users.noreply.github.com email address that appears below this checkbox
  4. Paste your @users.noreply.github.com email address into the command above to use your GitHub noreply email with git

Learning Git

Git is an incredibly useful tool, and is used very often in software development. It can be difficult to learn, but is worth the effort it takes.

Here are some resources I recommend for learning git: (More git resources will be added here soon)

Submit Your CS50 Assignment

You can use the following commands to submit your assignment. Below the steps are an explanation of what each command does.

Replace USERNAME with your GitHub username, and replace the/branch/from/the/assignment with the branch from the assignment’s How to Submit instructions (i.e. web50/projects/2020/x/search)

git init
git remote add origin https://github.com/me50/USERNAME.git
git switch -c the/branch/from/the/assignment
git add .
git commit -m "Add a commit message here"
git push -u origin the/branch/from/the/assignment

Most of these commands only need to be run the first time you push your code to GitHub. If you make changes and need to resubmit your code, the three commands below should be all you need:

git add .
git commit -m "Add a commit message here"
# Because we used the -u option before, we don't have to specify a remote and branch name again when we push.
git push

Command Details

You can run git help <command> (i.e. git help switch) or check the git docs to get more information about different git commands. The help pages for the commands below are linked.