ssh myuserid@hamilton.se.rit.edu
(put in your own SE userid!)Find PuTTY in the Programs menu and use it to login to hamilton.se.rit.edu
using your SE account and password. A few notes:
In PuTTY, if you use your mouse to select text on the PuTTY screen, it is automatically copied to the Windows clipboard. So if you want to copy text from your PuTTY console, just select, then switch to a Windows editor and paste
To paste from the Windows clipboard into your PuTTY console, use shift + insert. Right-clicking may also work.
Open a terminal (ctrl+alt+t) and type: ssh hamilton.se.rit.edu
. Login to hamilton using your SE account and password. A few notes:
To paste from the clipboard into your console, use shift + insert or ctrl+shift+v.
Create an SSH key pair
ssh-keygen -t ed25519 -C "email@example.com"
You will be prompted to input a file path to save your SSH key pair to. You should hit “enter” and nothing else to use the default path.
You may be prompted to input a password; feel free to enter a password.
For any other prompts, simply hit “enter” to take the default value for these other prompts. Once successful, you should see an ascii picture (a picture made of random characters). This means it worked.
Check out the public key you made in your .ssh file by typing cat ~/.ssh/id_ed25519.pub
You should see a something like: “ssh-ed25519” followed by random-looking characters and then your email address. This is your public SSH key.
Git is a powerful source code control system that allows developers to store their source code, collaborate, and manage changes. It is a key tool in any software engineer’s toolbox.
Git uses some terminology that we need to remember:
Working Tree: this is just a fancy name for the directory of your code, stored in directories.
Repository: the Git database of your project’s entire history. Everyone has a copy of the repository stored in a .git directory at the root of your working tree. You do not need to edit anything in there directly, only through a git command on the command line.
Add: take the changes to your working tree and get ready to store them in the repository.
Commit: store the changes from the add command into your local repository. When you commit, you need to write a descriptive message of the changes, and Git also records the timestamp.
Push: take the commits stored in your local repository and place them in a remote repository, thereby integrating your work with others’ work.
In this exercise, we will be focusing on how to use Git on the command line, including creating a repository, adding files, committing files, and pushing your changes to a remote repository.
In this course, Git is not just a tool for you to use, it’s your submission system. So understanding how to use Git is critical for for this course. If you mess up your submission, you won’t get credit for all your hard work.
You will be creating one personal repository for this entire course. As you work, you will be asked to make many commits at logical times. When you are ready to submit an assignment, then you will push your changes to your repository.
Let’s set up our username in git. You only need to do this once for the entire semester. In your terminal (e.g., putty logged into hamilton
), use the git config command for changing user.name and user.email, like this:
$ git config --global user.name "Bojack Horseman"
$ git config --global user.email "bjh9999@rit.edu"
A neat feature in git command line is to use the coloring scheme to more easily spot the status of things:
$ git config --global color.ui true
Now let’s go and create our repository on GitLab. GitLab is a web application that allows you to have a remote Git repository, much like GitHub. RIT has its own installation of GitLab that we will be using for this course. Go to https://kgcoe-git.rit.edu/. Keep this link-- you will NEED to use it to log in to gitlab. Do not google gitlab and try to access from there; it will not work.
Sign into GitLab using your RIT (not SE) username and password.
Create a “new project”, and name it swen-250
. Make sure the repository is private. make sure the project name is swen-250
exactly. Same spelling, same capitalization, using a dash. Failure to do follow this instruction to the letter may cause grading problems.
Give Reporter
permissions to your instructor and course assistant(s). You may need their usernames - be sure to ask if they have not provided it. To do this, you need to have your project page open. An easy way to make sure you have it open is to modify this link with your username: https://kgcoe-git.rit.edu/(YOUR_RIT_USERNAME_HERE)/swen-250. Go to Settings -> Members on the left side of the screen at the bottom. Add ALL of your TAs and Instructor as a member with Reporter
as the type.
Make sure you did step #4 completely. If you are confused, ask your instructor or TAs for help.
Now let’s add your ssh keys. You need to give Gitlab your public SSH key so that it can authenticate when you use git commands from hamilton
. To do this, go to the top rightmost of your screen. You should see a circular symbol with a dropdown arrow next to it. Click there, go to settings
then on the left you should see ssh keys
. Click on that. You should now see two text boxes. One for your key
and one for a title
.
Go back to the terminal window where you logged into hamilton
. If you are logged out, log back into hamilton. Now type cat ~/.ssh/id_ed25519.pub
again and copy that ENTIRE string starting with “ssh-ed25519” and ending with your email. Paste this string into the key
textbox on the gitlab page. Enter a title
for this key-- it can be anything; make it descriptive. Something like “hamilton ssh key”.
Now that we’ve created a repository on GitLab and added our SSH key, let’s clone
your new swen-250 repository onto hamilton
. Find the SSH URL for your swen-250
by clicking on Project . The SSH URL will look like git@kgcoe-git.rit.edu:(your_rit_username_here)/swen-250.git
(your username will be in there)
Back in PuTTY/your terminal, type cd ~
to make sure you are in your home directory, then use git clone
to clone the url. Your command will look something like this: `
git clone git@kgcoe-git.rit.edu:(your_rit_username_here)/swen-250.git`
ls
to be sure.Change directories into your repository folder on hamilton, using cd
Let’s add something to our working tree. Edit a text file called name.txt
.
If you have never used a command line text editor before, the simplest text editor is nano. Type nano name.txt
to create and edit the file, use hotkeys shown at the bottom - (e.g. ^X means Ctrl+X)
While nano is a mediocre, quick-and-dirty text editor, we strongly suggest learning a more feature-rich editor like vim as the course moves forward. Check out our resources page for more information on learning different editors.
In name.txt
, write your full name (so the instructor knows who you are). Save and exit the text editor.
Ok, now that we’ve written some “code”, we’ve completed our first task. So it’s a logical time to add, commit, and push our changes. First, let’s see where we stand. Type git status
. You should get output like this:
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add ..." to include in what will be committed)
#
# name.txt
nothing added to commit but untracked files present (use "git add" to track)
.gitignore
create and edit the file and add the following contents. Be careful that your copy/paste does not ruin the formatting:Copy starting from line below:
# This file will prevent Git from adding files that match the following
# patterns to the repository. If you need to add a file anyway, you can use `git add -f [file]`
# Text editor swap files
*.swp
*.swo
*~
# Compiled binary files
*.o
(Copy up to line above)
Note that git will not ignore a file that was already tracked before a rule was added to this file to ignore it. In such a case the file must be un-tracked, usually with git rm --cached filename
As we expect, we’ve got our new file to add. Add your changes to git by typing git add .
Running git status
now gives us the following output:
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached ..." to unstage)
#
# new file: name.txt
#
Now it’s time to commit. Committing your changes to source control generally means that you are in a relatively stable state. It does not mean that you are done with the assignment - that’s not committing enough for this class. Commit when when your program is compiling, and a piece of your work is done. The more often you commit, the easier it is to roll back to a stable state, and the more atomic and understandable your changes are.
To commit, type git commit
. By default, git will open up the vim text editor for you to enter your commit message. (If you would rather use nano to edit your commit messages, then run git config --global core.editor “nano”). Git commit messages have this convention:
The first line is the subject line, which is a concise description with a maximum of 50 characters
The second line is always blank
Anything on the third line and after is a more thorough description of the changes.
For this class, the most important element is a well-written subject line. “A few changes” is the worst possible commit message - be descriptive without being verbose (50 characters is short - this parenthetical is 49).
Write a descriptive message for adding the name file, such as “Recording my name for grading”.
Exiting out of the text editor will automatically finish your commit. When that is done, your output will look something like this:
[master (root-commit) 5d859e9] Recording my name for grading
1 file changed, 1 insertion(+)
create mode 100644 name.txt
push
. We need to push our commits to our remote repository on GitLab so the instructor can view it and grade it. Ok let’s push now. The command is git push origin master
. The output looks similar (but perhaps not exactly) to this:
Counting objects: 3, done.
Writing objects: 100% (3/3), 278 bytes | 278.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To kgcoe-git.rit.edu:cdnvse/swen-250.git
3063b61..3f82b4f master -> master
You’re all set up! We’ve synchronized our repository with our GitLab so that the instructor can see our changes. From here on, we can continue to modify, commit, and push our code right up to the deadline. Now try out the workflow below and review our tips.
Here’s the typical workflow we want you to use.
Start working by running git status. Commit or remove any changes you might have forgot to deal with before (i.e. start with a clean working tree).
Think about how you will break up this work into smaller tasks
Edit, compile, test (your typical programming workflow)
At the end of one of your mental tasks, add
and commit
.
Continue to complete your other tasks until the assignment is completed.
When you are ready to submit your assignment, push
your changes.
Double-check that all of your changes are pushed with git status
.
Double-check your changes are pushed to GitLab.
Learning this pattern of work is critical to your success as a future software engineer. Don’t wait to do Git stuff until the very end of your work.
For this exercise, let’s use our FizzBuzz code into our working tree.
Make a subdirectory for Fizzbuzz - called FizzBuzz.
Copy your FizzBuzz code into your FizzBuzz directory
Commit that code as-is.
Now add some comments to your FizzBuzz source code, and make any other code cleanup that you wish to make.
Commit those changes, giving a descriptive message.
Push to GitLab.
All of your assignment and projects will be in your personal repository for this course. To speed up grading, please name files and directories exactly as specified in the assignment or project description. Doing this properly is part of your grade.
To check that you have submitted, run these two commands
git status
- to make sure everything has been committed (should say “# On branch master nothing to commit (working directory clean)”)
git push origin master
- if it says “Everything up-to-date”, you have everything pushed and submitted
Deleted a file? Use either git rm
or git add -A .
to record that deletion.
Want to add, commit, push all in one command? Use:
git add . && git commit && git push origin master
Also, in bash, you can use the up arrow to bring that command back up quickly.
If you realize you don’t want to commit partway through, then exit your text editor with an empty commit message and everything aborts safely.
Interested in more Git features? Ask your instructor! It’s a very feature-rich tool.
Note: Git is not a misspelling of “get”, it’s a self-deprecating joke about Linus Torvalds
A correctly set up repository.
For this assignment, the instructor and graders will find for your repository on GitLab and make sure it’s set up properly.
There may come a time you need to accesshamilton
from OFF-CAMPUS. To do this, you will need to run RIT’s VPN. Refer to this page for instructions on how to access hamilton
off-campus: https://www.rit.edu/its/services/network-communication/vpn
The address for the vpn (you put this into the client) is: vpn.rit.edu