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, allowing you to revisit previous versions of your code or even work with different versions at the same time. 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 thirty years and GIT is currently the cool tool to use (Linus Torvalds, of Linux fame, created it out of necessity and frustration to help him manage the Linux source 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.
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, configure GIT for your computer (note, these commands need to be done 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://git.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 should be a warning at the top of the page saying you need to set up an SSH key
- 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 key using Eclipse
Generate an SSH Key
- Within Eclipse, go to
Window -> Preferences -> Network Connections -> SSH2
- Choose the tab
Key Management
and pressGenerate RSA Key...
- Copy the text that appears in the text area using Crtl-C (Windows) or Cmd-C (Mac)
- Press
Save Private Key...
and agree to save it without passphrase protection - Save it using the name
id_rsa
(no extension) so that it does not conflict with any other SSH keys you may have created in the past and pressOkay
to close the dialog box - Within a Browser, paste the copied public key into the 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 Action Menu, (the icon of three bars in the upper left corner) and select
Projects
-> Explore Projects
-> All
- Choose the project for this lab, CompSci308_2016Fall/lab_bins
- Press
Fork
and save the project in your own namespace with the same project name (e.g.,NetID/lab_bins
) - On the new project page that appears, copy the SSH URL (e.g.,
git@git.cs.duke.edu:NetID/lab_bins.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@git.cs.duke.edu:NetID/lab_bins.git
- That command should create a folder named
lab_bins
within your workspace folder that contains configuration information for both GIT (e.g.,.git
) and Eclipse (e.g.,.project
)
ls -a lab_bins
Importing Your Local Copy into Eclipse
- Within Eclipse, select
New -> Java Project
- Enter the name of the folder you just created:
lab_bins
, and pressFinish
note, if you type the project name in correctly, all options in the dialog box will grey out (become unedittable)
- It should create a project for you within Eclipse that has an annotation next to it referring to your repository name and
master
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
Resources
Submission
Play around with the lab_bins
repository, making changes locally through Eclipse, and push
ing those changes up to your Gitlab repository. You should commit at least three times and push
to Gitlab at least two times.