EGR 103/GIT

From PrattWiki
Revision as of 12:13, 25 August 2015 by DukeEgr93 (talk | contribs)
Jump to navigation Jump to search

Introduction

Starting in the Fall of 2015, students in EGR 103 will be using a program called git in order to back up their work for EGR 103, to put their work into a repository that is accessible to the TAs and instructors, and to get public files for the course from the instructors. While there is naturally some overhead associated with learning how the program works, understanding git is a valuable skill for people taking EGR 103 to have.

For EGR 103 for the Fall 2015 semester, students will be using Duke's Git server, gitlab.oit.duke.edu (referred to as Gitlab from this point on), to serve as a host for their git repository. Students will also be pulling a repository from Gitlab which contains files created during lectures and labs as well as files needed for lab each week. The following sections go through the process of setting everything up -- please be careful while following these instructions, and if you have any questions, ask a TA or the instructor for help. For Lab 1, you will just be setting up the connection to the public repository from which you will pull the files to start your work each week. During Lab 3, you will set up your own repository to save your work.

Lab 1 Processes

Getting the public repository

First, you will be creating a directory in your OIT account and then populating it with some public files that you need for lab this week. Each week from here on out, all you will have to do is update your local copy of this folder. For this week, you will need to create a space for the files then tell git where to get the necessary information. All of the commands below will be on the command line in your terminal (MobaXterm) window:

  • Go to your home directory:
cd ~
  • Tell git to clone a preexisting repository - this will automatically create a folder with the name of the repository and will put the files in it:
git clone git@gitlab.oit.duke.edu:mrg_public/EGR103F15public.git
  • Change the name of the folder to be a little shorter
mv EGR103F15public EGR103public

You should only ever need to issue the clone and mv commands for this folder once. From this point forward, if you want to get the most up-to-date version of the public repository, all you have to do is change into the EGR103public directory and pull the files:

cd ~/EGR103public
git pull

To make sure your folder is correctly connected to the repository, you can look at your configuration file. Make sure you are in the EGR103public folder and then type

more .git/config

The output should closely resemble:

[core]
        repositoryformatversion = 0
        filemode = false
        bare = false
        logallrefupdates = true
        ignorecase = true
[remote "origin"]
        url = git@gitlab.oit.duke.edu:mrg_public/EGR103F15public.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master

Setting up your EGR103 Folder

Next, you will set up the folder where you will be saving all your work. To do this:

  • First go to your home directory:
cd ~
  • Now create a folder called EGR103:
mkdir EGR103
  • Change into that folder:
cd EGR103
  • Create a folder for the first lab called lab1:
mkdir lab1
  • Change into that folder:
cd lab1
  • Copy the public files from the EGR103public/lab1 folder into your EGR103/lab1 folder. Since you are already in your EGR103/lab1 folder, you can use relative addresses:
cp -i ../../EGR103public/lab1/* .


Lab 3 Processes

During this lab, you will set up your own gitlab account, link your directory to it, and push your files to the repository. From this lab forward, you will need to push your EGR103 folder every time you have finished making edits to your files.

Setting up your Gitlab account and SSH Keys

To set up your Gitlab account, you will need to log in to Gitlab. To do anything with it, however, you will also need to give Gitlab a piece of code - known as an SSH Key - that Gitlab can use to confirm you are who you say you are. The following will go through the process of setting up your account, generating a key, and adding that key to Gitlab.

  • First, you will need to have a web browser open - it does not matter which one. Navigate to gitlab.oit.duke.edu
  • Do not put your NetID or password in the boxes; instead, click on the "Shibboleth" button: Git Shibboleth.PNG
  • At the Duke Sign In page, Log in using your OIT credentials
  • Click on the Profile Settings icon at the top right - it is the fifth icon from the left and resembles a person: Git Icons.PNG
  • In the Name box, put in your name, followed by your NetID in parenthesis. For example, Dr. G's is
Michael R. Gustafson II (mrg)
Be sure to include any number that forms a part of your NetID.
  • Click on the SSH Keys entry in the menu at the left of the page: Git Keys.PNG
  • Click on the Add SSH Key button at the right of the page: Git AddButton.PNG

Now you will need to generate a key and copy it into this space. To do that, you will need to log in to the Duke Unix machines and then issue Unix commands to have it create a key for you. The following commands will all be in a terminal window:

  • Open MobaXterm and, if need be, start a local terminal
  • At the prompt, type
ssh -XY NetID@login-teer.oit.duke.edu
where NetID is your NetID
  • When prompted, type your password; note that the cursor will not move as you type
  • To create an SSH Key, type:
ssh-keygen -t rsa -C "NetID@duke.edu"
where, again, NetID is your NetID.
  • Accept the default location, which should be /winhomes/NetID/.ssh/id_rsa
  • To see the SSH Key, type:
cat ~/.ssh/id_rsa.pub
  • To copy the SSH Key to your clipboard, simply select the text starting from ssh-rsa and ending with NetID@machine or NetID@duke.edu

You will now paste this key into the Key section of the "Add an SSH Key" web page in your browser. You can leave the title as the default case or give it a different name if you wish. Then click the Add Key button: Git AddKey.PNG

From this point forward, when any of the Teer machines interact with your Gitlab account, the keys will be used to verify that you are who you say you are.


Creating your class repository

For the next step, you will be working in the browser with the Gitlab page again. You will be creating a Group - which is the top-level organizational structure for Gitlab - and within that you will be creating a Project. The project will be where all your files for the class are backed up. You will be granting access to the instructors and the TAs to view the project for this class -- that will help us help you if need be and will also make it possible for us to grade some of your work online. Please carefully follow the process below:

  • If you don't already have a browser open and pointing at Gitlab, open a browser, navigate to gitlab.oit.duke.edu and log in using the Shibboleth button.
  • Click the Dashboard icon at the top left: Git Dashboard.PNG
  • If there is a tabbed window at right, select the “Groups” tab then click the “New group” button under the tab; if there is not a tabbed window at right, click the New Group button in the dashboard.
  • In group path, using YOUR NetID, put in NetID_classes - be sure to include the underscore character.
  • In the details block, write a note to yourself that this is the group where class pages go
  • Click the Create Group button - this should create the group and then go to the group’s page: Git CreateGroup.PNG
  • Click the New project button on the right: Git NewProject.PNG
  • In the Project path, type EGR103
  • Make sure the Visibility Level is Private: Git PrivateProject.PNG
  • Click the Create project button: Git CreateProject.PNG
  • Click on Settings at left: Git ProjectSettings.PNG
  • Click on Members, located directly under settings; the icon looks like a group of people: Git ProjectMembers.PNG
  • For the next part, you will be adding the instructors and your lab section TAs; their NetIDs will be written on the boards at the front of the room.
    • Click on the New project member button at right: Git NewProjectMembers.PNG
    • In the people box, add mrg
    • In the Project Access drop down, change to Master: Git AccessMaster.PNG
    • Click the Add users button Git AddUsers.PNG
    • Repeat these four steps for the four TAs and for the Head TA

Pushing your class directory

Finally, you can go back to your Unix account to link and push your folder. Go back into your terminal window and perform the following steps:

  • Change into your home folder
cd ~
  • Change into your EGR103 folder
cd EGR103
  • Make your EGR103 folder a repository
git init
  • Add all the folders inside your EGR103 folder to the first set of items to push to the repository
git add .
  • Commit all the items you just added to push to the repository
git commit -a -m "First Commit"
  • Connect your folder to your repository - be sure to replace NetID below with *your* NetID:
git remote add origin git@gitlab.oit.duke.edu:NetID_classes/EGR103.git 
  • Push your files to the repository
git push -u origin master

Of the commands above, you should only have to issue the init and remote commands once. From this point forward, you should be able to send your most updated version of your files to the repository by going into your EGR103 directory and then typing

git add .
git commit -a -m 'Message'
git push

Note in the latter case that you do not have to append the -u origin master part after the first push. If, for some reason, you need to retrieve an archive copy of your files, you can do this by going into your EGR103 directory and then typing

git pull

However, you will typically not need the git pull piece as the files on Unix will generally be the most updated. If you lost files, or edited them in a way that you need to recover an older version, git pull will be able to help you there.

General Practices

Whenever you first log in to do work for a new lab, you will want to make sure to get the most updated version of the public files; that process will be in the terminal window:

cd ~/EGR103public
git pull

You will then want to set up a folder for that lab in your own EGR103 folder and put your work there:

cd ~/EGR103
mkdir labNN
cd labNN

Finally, whenever you are finished working or if you just want to make sure to push any changes up to the repository, you will want to push your entire EGR103 folder up to the Gitlab server:

cd ~/EGR103
git add .
git commit -a -m 'Message'
git push

You must be sure to use the add, commit, and push commands before you log off the system. Not only will that back up your work but it will also put the files in a location where the instructors and TAs can see them to potentially help with coding issues you may be having. Also, sometimes your files will be needed for grading purposes - having the latest and greatest in your repository will make it possible to give you credit for your work.