GITing Started
Knowing how to use a source control system will be an invaluable tool for you going forward, perhaps personally, but especially in a team setting. At its heart, version control is just a way to manage the many changes that occur to your files over time, but that simple idea changes everything! It allows you to revisit previous versions of your code, work with different versions at the same time, and work in teams and track who made which changes. At its best, version control is like a journal that you use to track major, and minor, events in your project. At its most practical, it is like a backup system that prevents you from losing significant work if something happens to your machine. At its worst, it is simply a submit system where you only track your work when told to.
Version control systems have been around for over forty years and GIT is currently the cool tool to use (partly because it was created by Linus Torvalds, the creator of Linux, and partly because of the popularity of GitHub, the largest public repository of code). Using source control well is not difficult, but it does take some practice and a little bit of command-line savvy (we do not suggest using eGit, the Eclipse plug-in, until you are confident in your version control skills).
When running these programs, unless otherwise noted, we suggest following the default options. Here is a video of me setting up a JavaFX project in Eclipse from GitHub last year. It assumes you have already installed Java 9 and Eclipse.
Install Java and Eclipse
You will be using features from Java 8 in this course (but not necessarily Java 9). The latest version of Java includes JavaFX classes directly, so no additional software is needed to complete this step (specifically, we will not be using the separate tool, SceneBuilder, at all in this course).
- Download and install Java 9 SE JDK
- Download and install Eclipse IDE for Java Developers or IntelliJ (free for Duke students)
Install GIT
- Download and install GIT
on Mac or Linux, you can use the built in Terminal program to interact with GIT
on Windows, it comes with a program called Git Shell that you can use to enter the commands below - Within Terminal/Shell, configure GIT for your computer (note, these commands need to be done once for each computer you program on)
git config --global user.name "YOUR NAME" git config --global user.email "NETID@duke.edu"
Login to Gitlab
- Within a Browser, go to the website: https://coursework.cs.duke.edu/
- Press the
Shibboleth
button to log in using your Duke NetID - After you have successfully been logged in through Duke's standard log in page, there may be a warning at the top of the page saying you need to set up an SSH key.
If not, go toUser Settings-> SSH Keys
to set it up if you have never used our Gitlab site (coursework
). - Clicking on that link should take you to a page prompting you to paste the public part of SSH key into the given text area
- Next, we will get that public key
Generate an SSH Key
- Within a Browser, go to the website: https://coursework.cs.duke.edu/help/ssh/README
- If you have not already generated an SSH key for another class:
- Within Terminal/Shell, do Step 1 in the second section "Generating a new SSH key pair" and accept the defaults (steps 2 and 3)
ssh-keygen -t rsa -C "NETID@duke.edu" -b 4096
- Copy public part of the key using the command given in step 4 corresponding to your OS
- Within Terminal/Shell, do Step 1 in the second section "Generating a new SSH key pair" and accept the defaults (steps 2 and 3)
- If you have not already connected your current computer to our Gitlab site (
coursework
): - Within Terminal/Shell, copy the public key using the command given in Step 4 in the second section "Generating a new SSH key pair"
- Within a Browser, paste the copied public key into the Gitlab text area (
User Settings -> SSH Keys -> Key Text Area
)
giving it the same title:id_rsa
, and pressAdd key
Getting Your Own Copy of a Gitlab Project's Starter Code
- Within a Browser, click on the
Projects
menu along the top, then clickExplore Projects
-> All
- Choose the project for this lab, CompSci308_2018Spring/lab_bounce
- Press
Fork
and save the project in your own namespace with the same project name (e.g.,NetID/lab_bounce
)
Note, you will use fork to create your own repository of lab projects, but a repository will be provided for you for assignment projects (so no fork is needed) - On the new project page that appears, copy the SSH URL (e.g.,
git@coursework.cs.duke.edu:NetID/lab_bounce.git
)
Cloning Your Copy of the Project onto Your Local Machine
- Within Terminal, change to your Eclipse workspace folder
cd WORKSPACE/FOLDER
- Download a local version of the project that is linked to your Gitlab repository
git clone git@coursework.cs.duke.edu:NetID/lab_bounce.git
- That command should create a folder named
lab_bounce
within your workspace folder that contains configuration information for GIT (e.g.,.git
)
ls -a lab_bounce
Importing Your Local Copy into Eclipse
- Within Eclipse, select
New -> Java Project
- Enter the name of the folder you just created:
lab_bounce
, and pressFinish
Note, if you type the project name in correctly, all options in the dialog box will grey out (become uneditable)
- It should create a project for you within Eclipse that has an annotation next to it referring to your repository name and
master
- Within your
lab_bounce
folder should now be the configuration information for both GIT (e.g.,.git
) and Eclipse (e.g.,.project
)
ls -a lab_bounce
- Run the program to verify that your Java installation is working.
If there are compilation errors or it does not run, then you did not install the latest versions of Java or Eclipse or this project is not correctly configured.
Push Changes to your Project back up to Gitlab
- Within Eclipse, open the file
README.md
by double clicking on it - Add your name and save the file
When you do this, you should see a greater than sign,>
, appear next to the file that indicates GIT knows it has been changed - Within Terminal, add your changed files to those staged for your next commit
git add README.md
- Then note that all the added files should be grouped together into a single commit to the repository, with a message describing the changes contained in this commit
git commit -m "Included my name in the README"
- Push all your commits to the remote repository, e.g., Gitlab, so that others (UTAs, teammates, etc.) can see your changes
git push -u origin master
- Within a browser, refresh the page to see your changed README file
Make Substantive Changes
Complete the following tasks to practice the basic GIT workflow commands (add
, commit
, and push
), get used to JavaFX, and begin to think about how to organize code within a project. For each task, you may make any changes to the code you think are warranted (functional or organizational). After you think you have completed each task, make a GIT commit
with an appropriate comment (i.e., there should be at least four commits in your project history). After every two commits, push
your changes up to Gitlab so your online lab_bounce
repository reflects the work you have done in lab today.
- Make the bouncer "bounce" off of one "wall" (pick any edge of the JavaFX window) by reversing its direction
- Make the bouncer bounce off of all the walls, including the corners
- Make two bouncers that start at different places, with different sizes, move in different directions, but with both bouncing off of all the walls
- Make any number of bouncers, with different random initial properties, that bounce around
Resources
- GIT Commands Visualization
- GIT Commands Summary Page
- Visual GIT Reference
- Understanding Version Control Systems
Submission
What is in your lab_bounce
repository on Gitlab at the end of lab is what will be considered your submission. This is how all submissions will be done for this course — only what is in your Gitlab repository will be considered part of your classwork.