Skip to content

Instantly share code, notes, and snippets.

@727021
Last active April 6, 2024 04:18
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save 727021/d83624bdea9b971644e5289332dc66f5 to your computer and use it in GitHub Desktop.
Save 727021/d83624bdea9b971644e5289332dc66f5 to your computer and use it in GitHub Desktop.

Git50 - Submitting CS50 Assignments with Git

This guide is now its own website!

For the most recent version of this guide, please visit https://git50.schim.dev.








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.

  • git init - Creates a new empty repository on your computer.
  • git remote add origin https://github.com/me50/USERNAME.git - Adds a remote to your repository named origin that points to your me50 repository on GitHub. A remote is like a shortcut for a git URL.
  • git switch -c the/branch/from/the/assignment - Creates a new branch called the/branch/from/the/assignment and switches to it. Each assignment will need to be submitted to a different branch.
  • git add . - Stages all of the changes in your current directory. Staged changes are what git will include when you make a commit. You can specify individual files instead of . if you only want to add and commit some of your changes.
  • git commit -m "Add a commit message here" - Creates a commit with all of your staged changes. A commit is like a snapshot of your code. You can create multiple commits as you work to keep track of changes made to your code over time. Only staged changes are used when committing, so make sure you run the git add command above before you make a commit. It's also helpful to use a short, meaningful commit message when you make a commit (something like "Finished requirement 1" is usually better than "submitted" or "commit message"), in case you need to look back at your commit history.
  • git push -u origin the/branch/from/the/assignment - Pushes your committed code to the the/branch/from/the/assignment branch on your origin remote. The -u option sets up the current branch in your local repo to track the remote branch you pushed to, so you won't need to specify a remote and branch name when you push in the future. Remember that only committed changes are pushed; pushing commits to GitHub is different than just uploading your code somewhere.
@tjadziki
Copy link

Thank you so much

@savetheword
Copy link

👍

@abubakrmughal
Copy link

Thank you

@iwanbotha
Copy link

what if i use the git website to put files in the correct branches?

@savetheword
Copy link

?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment