Git Repositories

Installing Git

If it is not already installed on your system (just try typing git --version in an open shell/terminal on your computer), you can download the latest version of Git from the official website. The documentation section of the site has a good overview of how to get started and the basic workflows for committing source code, pushing to and pulling from repositories, etc. If you haven’t used Git before, you can try out the basic steps while you set up your own repository on MSU’s GitLab server for the homeworks, as described below.

Setting Up Your Homework Repository

We will use a simple workflow for submitting computational homework via Git. Follow these steps to set things up:

  1. Log into MSU’s GitLab server with your NetID, and create a new project named PHY422-820.

  2. Go to the project settings via the side menu, and add me (NetID: hhergert) as a project member with Developer permissions. This will allow me to actively push modifications to your project (e.g., fixes) if necessary, rather than just comment on your code.

  3. Clone the project to your local machine (git clone). This will also set up the associations for pulling and pushing code from and to your repository on the GitLab server. For convenience, you can get the URL for your repository by clicking on the Clone button on your GitLab project screen. Check your repository associations to see if everything was set up properly - you should get the following output:

    $ git remote -v show 
    origin  https://<your netid>@gitlab.msu.edu/<your netid>/phy422-820.git (fetch)
    origin  https://<your netid>@gitlab.msu.edu/<your netid>/phy422-820.git (push)
    

    or

    $ git remote -v show 
    origin  git@gitlab.msu.edu:<your netid>/phy422-820.git (fetch)
    origin  git@gitlab.msu.edu:<your netid>/phy422-820.git (push)
    

If you are going to primarily access the repository from an off-campus network, you should use the HTTPS link. The SSH version will only work if you are connecting from MSU Wireless or some other campus network.

Submitting a Homework Set

If you do not specify otherwise, your local work will be committed to the repository’s master branch, which will get pushed to origin/master. Under the default settings of a GitLab project, this branch is protected, i.e., the owner is the only user allowed to push chode changes.

To allow the instructors to push suggested changes (and not just review your work via the web forms), and to facilitate tracking, we will use a branch with the cleverly chosen name submit to submit your homework each week.

Submitting for the First Time

  1. Perform a git pull from the course repository to get the most recent version of the materials, including any Jupyter notebooks for a numerical homework problem.

  2. Copy the homework to your local homework folder (which should be separate from the one into which you cloned the materials repository).

  3. Switch to your local folder and type (notice the dot)

    git add .
    
  4. Now type

    git status
    

    It should tell you that a new file has been added, or some tracked files have changed.

  5. Type

    git commit -m “<some message>"
    

    This will add the current version of the notebook to your local repository. After you’ve made some changes, work repeat steps 2 through 4.

  6. Push new commits to the GitLab project by typing

    git push
    

    The default setting is to push the currently checked out branch to a the remote branch it tracks – most likely local master to remote master branch. You can check the tracking for different branches using git remote -v show,

    You can see which branch is currently checked out by typing

    git branch
    

    which will show you all local branches, and highlight the current one with an asterisk and color. You can create new branches with

    git branch <new branch name>
    

    and switch to that branch via

    git checkout <new branch name>
    

    If you have created any new branches that you want to store, the command is

    git push origin
    

    (which will create a new branch of the same name at the remote location), or

    git push origin <specific branch name>
    

    which will push the local branch to a remote branch with a specific, possibly different name.

  7. When you’re ready to hand in your homework, commit the notebook I’m supposed to review to the submit branch (you may have to create it), and push the submit branch to the GitLab server.

More details on the workflows and commands can be found in the official documentation, in particular the “Getting Started” section.

General Workflow

The workflow for any computational homework looks like this:

  1. Perform a git pull from the course repository to get the most recent version of the materials, including any Jupyter notebooks for a numerical homework problem.

  2. Carry out your work, creating branches and commiting code as needed.

  3. When ready to submit, commit your work to the submit branch.

  4. Push the submit branch to the GitLab server by the beginning of class on the homework due date.