Skip to content

Using GitHub to submit your assignments

juliengs edited this page Jul 16, 2018 · 1 revision

This page describes how to use the GitHub command line to work on your assignments and to submit to an appropriate branch.

0) Installing GitBash

Windows users: if not done already, please download and install GitBash, as you will need this software to run the Git commands. https://git-scm.com/downloads

MacOSX and Linux users: the procedure will be different, but once installed, the Git commands will be the same. On Linux, Git might already be installed.

For all the following steps, you will use Git Bash, so please open it. You should see a console window.

1) Setting up your name and email address

You will need to do this only once. Git will tell you upon committing if it's not already done.

Execute the two following commands. You can Copy and Paste them (to paste, right click in the console, and select Paste. Ctrl+V will not work in the console). Replace John Doe and [email protected] by your real name and email address

git config --global user.name "John Doe"
git config --global user.email [email protected]

2) Cloning your GitHub repository on your computer

You mst "cloning" (copying) the contents of your GitHub.com repository on your computer. You should do this only once.

In GitBash, navigate to the folder in which you would like to import your GitHub repository (i.e., such as the Desktop folder, on Windows). As the default folder is your user profile (in Windows), to reach the Desktop, you would typically need to type cd Desktop.

Helpful commands:

  • cd directory: to navigate to directory
  • ls: to view the files in the current directory

Tip: you can press [Tab] to complete a directory or file name.

To perform the clone, you need to find out the URL to your repository, on www.github.com. Open up the page corresponding to your repository, click on the "Clone or Download" button, and copy the link. The address should start with https://github.com....

To clone, type:

git clone url_of_your_repository

If this is the first time you clone your repository, it will be empty, except for a README.md file. You should then copy your project manually to the folder on your computer where you did the clone (using the Windows Explorer on Windows, or the Finder on Mac).

3) Pull the latest commits from GitHub

There might be some commits on GitHub that you do not have on your computer (might be the case if you work on two computers, i.e. with your teammate). To pull the latest commits from GitHub, type:

git pull origin master

4) Pushing your changes to GitHub

After working on your assignment, you should commit your changes, and push them to GitHub.

First, find out which files were modified:

git status

Mark the modified files for inclusion in the next commit. Ideally, you should add each file individually, as there might some files that you might wish to exclude from the addition.

To add a given file,

git add file_to_add

To save some time, you can also mark all files for addition in one operation:

git add .

Then, commit your changes. This will create a new commit on your computer with all the changes you made.

git commit -m "Briefly describe the changes in a few words here"

Finally, push your new commit(s) to GitHub - master branch

git push origin master

At this stage, you can check in your browser on www.github.com to see that your commit was properly propagated.

When you keep working on your project, you should repeat the cycle add-commit-push - this section (#4)

5) Submitting an assignment

When working on your assignments, you typically work in the master branch, which is the default, general-purpose branch. As per our submission process, we ask that you submit to a specific branch, assignment-X (X being the assignment number, 1 to 4), as our tools will automatically extract your commits on that particular branch. Please make sure that you respect this naming convention!

A branch will allow your work to be frozen in time, so that you can keep working towards your next assignment(s) in the master branch without impacting your submission for assignment X.

To submit to branch assignment-X, if you did not already create it, you first have to create the branch assignment-X (don't forget to replace X!):

git branch assignment-X

Then, you need to tell Git to switch to that branch as the currently active one:

git checkout assignment-X

You then tell Git to push your commits to that specific branch:

git push -u origin assignment-X

Finally, you should revert to the master branch to continue your work:

git checkout master

Optional: to check your current local branches:

git branch

The currently active branch will be denoted by a *

Optional: to check the branches that currently exist on GitHub.com:

git branch -r

You can also verify what your assignment-X branches contain online by browsing to www.github.com, opening your project, clicking on branches and looking at the contents of your assignment-X branches.

If you made last-minute changes (but before the deadline!) and you wish to push these latest changes to your assignment-X branch which already contains commits, then you simply need to go through this section (#5) again, but you need to omit the first command (i.e., git branch assignment-X), as the branch already does exist. Simply checkout that branch, push to it, and then get back to the master branch.