CSCI git project and lab submission

There is a Git Submit FAQ in the department tutorials.
For general git commands and info, see these git notes.

It is crucial that you read and understand these instructions all the way through before beginning, then:
think about what each step is trying to achieve,
before you hit enter, re-read what you actually typed in,
read and try to understand any warnings or error messages that are displayed before proceeding further...

Cutting and pasting chunks of instruction into your command window has a high probability of blowing up

This project code, examples, assignments, quizzes, labs, and other related material may be distributed and collected through the use of the git version control tool.

The basic idea is as follows, detailed instructions are provided afterwards:

Specific instructions

Note that the examples below are based on csci265 and an assignment named phase1, you will need to make appropriate substitutions in the commands if you are using these instructions for a different course or for another lab/assignment/project phase.

Step 1 is done once only at the start of the first lab, while steps 2-4 will be done once for each assignment/lab/project phase.

  1. Once only, at the start of the first lab, on otter (or one of the pups or cubs) create a directory for your csci265 material:
    mkdir ~/csci265

    For each of steps 2-4 check that you are entering the command as shown below, your only substitutions should be for the course number (instead of 265) and the assignment name (instead of phase1). Be very careful, and be sure you complete each step successfully before moving on to the next. Only do step 5 if/when the instructor explicitly asks you to.

  2. You can see your current central repository information using the command
    ssh csci info
    For each repository you have access to, this shows the name of the repository, and one or more of RWC (for Read access - you can fork/clone it, Write access - you can push to it, Creator - you created it)

  3. At the initial release of each phase/quiz, create your own fork of it on the central repository using the command:
    ssh csci fork csci265/phase1 csci265/$USER/phase1
    (note the command is shown for a project/lab named phase1, for one called phase2 you would substitute phase2 for phase1, for quiz1 you would substitute quiz1, etc)

    *If you find you are getting warnings about x11 when you run the ssh command, you can include the option -x to prevent them.

    Note that this creates a repository of your own on the central server containing a copy of the instructor's repository, including all the branches.

  4. Once you have your central version set up, it is time to create a working copy in your own account. This is done as follows:
    cd ~/csci265
    git clone csci:csci265/$USER/phase1
    cd phase1
    If step 2 or step 3 didn't work, and all you see in the new repository is a single default README file (e.g. if you forgot to fork, or made a mistake in the fork command but did the clone anyway), or you simply want to start all over, then you can try the following fix:
    1. Remove the local directory, e.g.
      rm -r phase1
    2. Move the mistakenly forked central repository to the trash repository, e.g.
      ssh csci D trash csci265/$USER/phase1
    3. Go back to your fork/clone and try again

    If you would like to see what you have put in the trash,
    ssh csci D list-trash
    If you would like to get something out of the trash, use the name/date of the file to restore as seen in the listing above, e.g.
    ssh csci D restore csci265/$USER/phase1/2016-02-10_14:00:00

  5. Now you can add the instructor's repository as an upstream so you can fetch updates from the instructor if necessary:
    git remote add instructor csci:csci265/phase1

    Type in ls to verify that the expected files were copied across.

  6. How to fetch a new version from the instructor if the instructor tells you an update has been posted and needs to be fetched:
    Note: hopefully git will soon allow us to drop the term "master" to refer to the original branch, replacing it with something like "primary"
    If an update is issued you can retrieve it using
    (5a) git fetch instructor
    You can then see what has changed using
    (5b) git diff HEAD instructor master
    You can then make any changes needed and merge the instructor's master into yours with
    (5c) git merge instructor master
    Note that if there are conflicting changes between the instructor files and your own then it will let you know what files need to be edited to resolve the changes, and once it completes it will open an editor window for you to enter a commit message.
    An alternative is to use
    git pull instructor master
    which will automatically carry out the merge (fetch is nice/safer in that you can use git diff to see what has changed and then choose whether or not to begin the merge process).
    Again, you may need to resolve conflicting changes and it will open an editor window at the end for you to enter a commit message.

  7. You can edit and save any changes you need to in your working copy as you work on the phase/quiz, committing them using
    git add filename (to include your added/changed file for the next commit)
    git add . (to add all your added/changed files for the next commit)
    git rm filename if you want to get rid of a file (-r for directory)
    git mv oldname newname if you want to move or rename a file or directory
    git add -u (so any files you've removed locally also get removed from the repository)
    git commit -m "---some message describing the change---"
    (to actually create the commit point and associate a message with it)

    Commit whenever you have a new feature working or when you are about to try a change that might not work out.

  8. Submit the master branch of your updated solution to the central repository using
    git push

More options to explore:

If you want to check for added or committed differences between your current local repository and your central repo, use
git diff origin/master...HEAD
(It should come up with nothing if you've pushed all your changes, but it won't detect local changes without the appropriate git add.))

You can check the status of your local repository (to see if you've forgotten any adds or commits) using the command
git status

  • if everything is up to date we should see "up-to-date with origin/master"
  • if we've committed but not yet pushed then we should see "ahead of origin/master by 1 commit" (or more than 1 possibly)
  • if we've added but not yet committed then we should see there are "changes to be committed"
  • if we've changed files but not yet added them we should see there are "untracked" files

If you want to push another branch, use the command
git push origin NameOfTheBranch

If you want to push all branches, use the command
git push origin --all

Note the commands above assume the master branch is the one of interest. If you want to see if there are other branches available you can use the command
git branch -a
If you want to then copy any of those branches to your local version you can use the command
git pull origin NameOfTheBranch
If you want to clone a specific branch you can use the following
git clone csci:csci265/$USER/item --branch thebranchname