Git Exercise
COP-3402
Table of Contents
1. Overview
In this project you will create a git repository and submit it to the grading server.
2. Log in to eustis
Be sure to do the first homework, which provides per-OS instructions for setting up ssh
.
ssh
into eustis, replacing NID
with your UCF NID.
ssh NID@eustis.eecs.ucf.edu
3. Configure git
You only need do this once for the entire semester.
3.1. Set user name
Replace "John Doe" with your full name.
git config --global user.name "John Doe"
There will be no output. If you get any output, double-check the command and re-enter it.
Validation
git config --global user.name
The output should be the full name you put.
3.2. Set your email address
Replace "johndoe@example.com" with your ucf email address.
git config --global user.email johndoe@example.com
Validation
git config --global user.email
The output should be the email address you put.
3.3. Set your editor to emacs
git config --global core.editor emacs
Validation
git config --global core.editor
The output should be emacs
.
3.4. Explicitly set the default branch name to master
This is the current default and what our grading tools will expect when pulling your projects.
git config --global init.defaultBranch master
Validation
git config --global init.defaultBranch
The output should be master
.
4. Create your repository
You only need to do this once per project.
For instance, you only need to do this once for git, only once for hello, etc.
When following these directions for other projects, do not use git
as the name of the repo, instead replace it with the name given in the project. For example, the hello
project will have local directory ~/cop3402spring25/hello
and URL gitolite3@eustis3.eecs.ucf.edu:cop3402/$USER/hello
.
4.1. Create a new directory
mkdir -p ~/cop3402spring25/git
The output should be nothing. Note that -p
will create all directories in the path if needed. If the path exists, it will not throw an error. The tilde ~
is an alias for your home directory, which on eustis is /home/net/NID
for your NID.
Validation
ls -d ~/cop3402spring25/git
The output should be ~/cop3402spring25/git
If you see the following
ls: cannot access '/home/net/NID/cop3402spring25/git': No such file or directory
then double-check your spelling and try creating the directory again.
4.2. Change the working directory to your new one
cd ~/cop3402spring25/git
The output will be nothing.
Validation
readlink -f ./
The output will be the full path to the current folder. Check it carefully. It should look like this:
/home/net/NID/cop3402spring25/git
If you get an error like the following,
-bash: cd: /home/net/NID/cop3402spring25/git: No such file or directory
then double-check your spelling and/or try creating the directory again.
4.3. Initialize the git repository
git init
The output should be
Initialized empty Git repository in /home/net/NID/cop3402spring25/git/.git/
Double check the folder path to make sure it is correct. If not try creating the directory again.
Validation
git status
the output should be
On branch master No commits yet nothing to commit (create/copy files and use "git add" to track)
The branch name should be master
if not then go back to make sure git config is setup correctly.
Errors
If you see the following,
hint: Using 'master' as the name for the initial branch. This default branch name hint: is subject to change. To configure the initial branch name to use in all hint: of your new repositories, which will suppress this warning, call: hint: hint: git config --global init.defaultBranch <name> hint: hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and hint: 'development'. The just-created branch can be renamed via this command: hint: hint: git branch -m <name>
then go back to make sure git config is setup correctly.
4.4. Add your first file
echo "git project" > README.md
You should see no output.
Validation
readlink -f README.md
The output will be the full path of the file. Look at it carefully. It should look like
/home/net/NID/cop3402spring25/git/README.md
Now enter
git status
The output will now show that README.md is untracked, i.e., it has not been staged and commited to the local repository yet. It is only in your working tree.
On branch master No commits yet Untracked files: (use "git add <file>..." to include in what will be committed) README.md nothing added to commit but untracked files present (use "git add" to track)
Errors
If you see the following,
fatal: not a git repository (or any parent up to mount point /home) Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
then you haven't yet initialized your git repository or you are not in the right directory.
4.5. Stage the file
git add README.md
The output should be nothing
Validation
git status
This should result in the following output, which tells you that the file is staged but not commited yet:
On branch master No commits yet Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: README.md
Double-check that the name of the file is README.md
.
Errors
If you see
fatal: not a git repository (or any parent up to mount point /home) Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
then you haven't yet initialized your git repository or you are not in the right directory.
If you see
fatal: pathspec 'README.md' did not match any files
4.6. Commit the file
Before committing, double-check that you configured your editor,
git config --global core.editor
The output should be emacs
(or the editor you selected). If not go back and be sure that git config is setup correctly.
To commit the file:
git commit README.md
This will open up your editor automatically and present you with the following text
# Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # On branch master # # Initial commit # # Changes to be committed: # new file: README.md #
The cursor will already be on the first line. Type your commit message, e.g., "Add a README.md file", so that your text now looks like this:
Add a README.md file # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # On branch master # # Initial commit # # Changes to be committed: # new file: README.md #
Then save the file and exit the editor (in emacs this is Ctrl-x Ctrl-s
then Ctrl-x Ctrl-c
).
The output should be
[master (root-commit) 0721d93] Add a README.md file 1 file changed, 1 insertion(+) create mode 100644 README.md
0721d93
is the commit ID, which will differ for you.
See this description of good practices for writing commit message.
Validation
git status
The output should be
On branch master nothing to commit, working tree clean
Now enter
git show
The output should be
commit 0721d935b05f1e506621893a00afbd6a70b7d5c4 (HEAD -> master) Author: John Doe <johndoe@example.com> Date: Thu Dec 19 11:20:43 2024 -0500 Add a README.md file diff --git a/README.md b/README.md new file mode 100644 index 0000000..74788a2 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +git project
The commit ID, author, and date should differ, but otherwise be the same. This is the changelog you have created.
Now enter
git log
The output should be
commit 0721d935b05f1e506621893a00afbd6a70b7d5c4 (HEAD -> master) Author: John Doe <johndoe@example.com> Date: Thu Dec 19 11:20:43 2024 -0500 Add a README.md file
The commit ID, author, and date should differ, but otherwise be the same. This is the history of changes, which shows only the commit ID, author, date, and first line of the commit message. Since this is your first change, there is only one log entry.
Errors
If you see
fatal: not a git repository (or any parent up to mount point /home) Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
then be sure you have initialized your git repository and are in the right directory.
If you see
error: pathspec 'README.md' did not match any file(s) known to git
then make sure you have staged the file already.
If you see
Aborting commit due to empty commit message.
then make sure you have typed in the commit message and saved the file.
4.7. Add the submission repository URL
Type the following:
git remote add submission gitolite3@eustis3.eecs.ucf.edu:cop3402/$USER/git
The output should be nothing.
Validation
git remote -v
This should output the following
submission gitolite3@eustis3.eecs.ucf.edu:cop3402/NID/git (fetch) submission gitolite3@eustis3.eecs.ucf.edu:cop3402/NID/git (push)
except that NID should be your actual UCF NID, e.g., ab123456
.
Errors
If you see
error: remote submission already exists.
then you have already added the remote. Double-check that it is the right repo url and the remote name (submission). If not, do the following to remove the submission url and re-add it.
git remote rm submission
then re-add the submission.
4.8. Set the upstream branch and push
git push --set-upstream submission master
You may see a request to check the host's fingerprint. You can say yes, although in general when connecting to a remote machine, you should independently confirm that the host's key matches the actual key on the server and that you trust the server.
Afterwards, the output should be something like this:
Welcome to eustis.eecs.ucf.edu. Please use your NID and NID password to log in. Your NID should be 2 letters followed by 6 digits. See http://t.cs.ucf.edu/help/eustis for additional instructions. Initialized empty Git repository in /home/gitolite3/repositories/cop3402/NID/git.git/ Enumerating objects: 3, done. Counting objects: 100% (3/3), done. Writing objects: 100% (3/3), 238 bytes | 238.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 To eustis3.eecs.ucf.edu:cop3402/NID/git * [new branch] master -> master Branch 'master' set up to track remote branch 'master' from 'submission'.
This will push your local repository to the remote, grading repository URL. Additionally it will remember that your local repository's master branch is mapped to the submission repository's master branch, so you only need to the type git push
for future submissions.
Validation
git status -sb
This should output the following
## master...submission/master
which confirms the mapping between your local repo and the submission repo.
Now enter
git branch -vv
The output should look like
* master 0721d93 [submission/master] Add a README.md file
The commit ID will differ, but this also shows the submission/master is the remote repo mapped from your local repo.
Errors
If you see a login prompt like this
Welcome to eustis.eecs.ucf.edu. Please use your NID and NID password to log in. Your NID should be 2 letters followed by 6 digits. See http://t.cs.ucf.edu/help/eustis for additional instructions. NID@eustis.eecs.ucf.edu's password:
then make sure you have added the submission remote repo correctly. Check that the server URL starts with gitolite3@
and not your own NID. Your own NID will be later in the URL after the cop3402/
, but it won't be the username before the @
symbol.
If you still see the above error, you have double- and triple- checked the URL, copied instead of hand-typed it, editing only the NID part and confirming that it is your NID, especially if you joined the class after the semester started, then it may be that you have not been given access to git yet. Please contact the instructor.
If you see
fatal: 'submission' does not appear to be a git repository fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
then make sure you have added the submission remote repo with the correct name submission
.
error: src refspec maste does not match any error: failed to push some refs to 'master'
then make sure you have initialized your git repository.
If you see
fatal: No configured push destination. Either specify the URL from the command-line or configure a remote repository using git remote add <name> <url> and then push using the remote name git push <name>
then be sure you have already set the upstream.
If you see
To eustis3.eecs.ucf.edu:cop3402/NID/git ! [rejected] master -> master (fetch first) error: failed to push some refs to 'eustis3.eecs.ucf.edu:cop3402/NID/git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
then have already pushed a local repository to the grading repo and are trying to submitting a new git repo. Please see these instructions to clone your existing repo and add whatever new changes you have.
If you see a request to enter your password, double-check your NID and that you have logged into eustis
and not eustis3
.
5. Making change logs
5.1. Edit your README.md file
emacs README.md
Make changes to the file, e.g.,
git project This project will exercise the use of the git version control tool on the command-line.
Then save and exit (for emacs, Ctrl-x Ctrl-s
then Ctrl-x Ctrl-c
).
Validation
Type
git status
You should see the following,
On branch master Your branch is up to date with 'submission/master'. Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: README.md no changes added to commit (use "git add" and/or "git commit -a")
Double-check that you see "modified" for the file under "Changes not staged for commit". This means that your working tree has changed, but the changes aren't staged yet (or committed or pushed). In this state, your project has not been submitted and graders will not see what you see in your working tree.
Enter
git diff
The output should look something like the following (with different commit IDs):
diff --git a/README.md b/README.md index 74788a2..2f11c4f 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ git project + +This project will exercise the use of the git version control tool on the command-line.
This will show you the differences you have made in your working directory.
Errors
If you see
fatal: not a git repository (or any parent up to mount point /home) Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
then you haven't yet initialized your git repository or you are not in the right directory.
If you see
fatal: pathspec 'README.md' did not match any files
then you haven't created the file yet.
If you see
nothing to commit, working tree clean
5.2. Stage the file
git add README.md
The output should be nothing
Validation
git status
This should result in the following output, which tells you that the change is staged but not commited yet:
Your branch is up to date with 'submission/master'. Changes to be committed: (use "git restore --staged <file>..." to unstage) modified: README.md
Double-check that you see "modified:" with the filename under "Changes to be committed". p
Errors
If you see
fatal: not a git repository (or any parent up to mount point /home) Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
then you haven't yet initialized your git repository or you are not in the right directory.
If you see
fatal: pathspec 'README.md' did not match any files
5.3. Commit the file
Before committing, double-check that you configured your editor,
git config --global core.editor
The output should be emacs
(or the editor you selected). If not go back and be sure that git config is setup correctly.
To commit the file:
git commit README.md
This will open up your editor automatically and present you with the following text
# Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # On branch master # # Initial commit # # Changes to be committed: # new file: README.md #
The cursor will already be on the first line. Type your commit message, e.g., "Add a README.md file", so that your text now looks like this:
Add a project description to README.md # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # On branch master # # Initial commit # # Changes to be committed: # new file: README.md #
Then save the file and exit the editor (in emacs this is Ctrl-x Ctrl-s
then Ctrl-x Ctrl-c
).
The output should be something similar to
[master 886c6f7] Add a project description to README.md 1 file changed, 1 insertion(+), 1 deletion(-)
The commit ID will differ for you.
Validation
git status
The output should be
On branch master Your branch is ahead of 'submission/master' by 1 commit. (use "git push" to publish your local commits) nothing to commit, working tree clean
Notice that it says your branch is ahead of 'submission/master' by 1 commit. That means you have local change that are committed (i.e., no longer only in the working tree), but that are not yet synchronized with the remote grading repo.
Now enter
git log
The output should be
commit 886c6f73f32a6f283b9b0ff1a4a66d270926e1f0 (HEAD -> master) Author: John Doe <johndoe@example.com> Date: Thu Dec 19 12:01:26 2024 -0500 Add a project description to README.md commit 0721d935b05f1e506621893a00afbd6a70b7d5c4 (submission/master) Author: John Doe <johndoe@example.com> Date: Thu Dec 19 11:20:43 2024 -0500 Add a README.md file
The commit ID, author, and date should differ, but otherwise be the same. Notice there are two log entries, one from the initial creation of README.md and one from your new edit. Also notice that after the commit idea there is (submission/master)
for the first commit (on the bottom), which tells you that this is the latest commit synchronized with the remote grading repository. The latest commit (on top) says (HEAD -> master
) which tells you that this is the most recent change of your local repository. The next step will be to push, which will ensure that any local (committed) changes are synchronized to the remote grading repository.
Errors
If you see
fatal: not a git repository (or any parent up to mount point /home) Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
then be sure you have initialized your git repository and are in the right directory.
If you see
error: pathspec 'README.md' did not match any file(s) known to git
then make sure you have staged the file already.
If you see
Aborting commit due to empty commit message.
then make sure you have typed in the commit message and saved the file.
5.4. Push the new changes
git push
The output should be something like this (but with different commit IDs).
Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Writing objects: 100% (3/3), 264 bytes | 264.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 To eustis3.eecs.ucf.edu:cop3402/NID/git 0721d93..886c6f7 master -> master
This will push any new changes to your local repository to the remote grading repository URL.
Validation
git log
commit 886c6f73f32a6f283b9b0ff1a4a66d270926e1f0 (HEAD -> master, submission/master) Author: John Doe <johndoe@example.com> Date: Thu Dec 19 12:01:26 2024 -0500 Add a project description to README.md commit 0721d935b05f1e506621893a00afbd6a70b7d5c4 Author: John Doe <johndoe@example.com> Date: Thu Dec 19 11:20:43 2024 -0500 Add a README.md file
Notice that now the latest commit (on top) has, after the commit ID, (HEAD -> master, submission/master)
, which means that both your local repo master
and the remote grading repo submission/master
are synchronized to the latest change.g
The commit ID will differ, but this also shows the submission/master is the remote repo mapped from your local repo.
Errors
If you see
error: src refspec maste does not match any error: failed to push some refs to 'master'
then make sure you have initialized your git repository.
If you see
fatal: No configured push destination. Either specify the URL from the command-line or configure a remote repository using git remote add <name> <url> and then push using the remote name git push <name>
then be sure you have already set the upstream.
If you see
To eustis3.eecs.ucf.edu:cop3402/NID/git ! [rejected] master -> master (fetch first) error: failed to push some refs to 'eustis3.eecs.ucf.edu:cop3402/NID/git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
then have already pushed a local repository to the grading repo and are trying to submitting a new git repo. Please see these instructions to clone your existing repo and add whatever new changes you have.
If you see a request to enter your password, double-check your NID and that you have logged into eustis
and not eustis3
.
6. Muscle Memory
Once you have configured git and setup a repo, the following is the workflow for making changes to your repository and synchronizing with the remote.
emacs file.c # edit, then exit and save (Ctrl-x Ctrl-s then Ctrl-x Ctrl-c) git add file.c git commit file.c # enter a commit message, then exit and save (Ctrl-x Ctrl-s then Ctrl-x Ctrl-c) git push git status # to validate your work
7. (Optional) Deleting a file
7.1. Stage the deletion
Use
git rm filename
to remove a file named "filename" from the repository. It will also remove it from the working directory.
You should see something like
rm 'filename'
as the output. Then follow the same directions as editing or adding a file to commit and push the file deletion. Note that the deleted file will still be recorded in the repository's log.
Validation
Part of the output should contain something like the following:
Changes to be committed: (use "git restore --staged <file>..." to unstage) deleted: filename
There may be other information in the output, but this part shows that the file deletion is staged for commit. Once you commit the change the file will be removed from the local repo and, once pushed, from the remote repo.
Errors
If you see
fatal: pathspec 'filename' did not match any files
then the file is not part of the git repository yet and you do not need to remove it.
8. (Optional) Cloning a fresh copy of your repo
8.1. Move your new local repo out of the way
mkdir -p ~/cop3402spring25/archive mv ~/cop3402spring25/git ~/cop3402spring25/archive
Validation
There should be no output if this is successful.
Errors
If you see this
mv: cannot overwrite '~/cop3402spring25/archive/git: Directory not empty
then you have already archived a git repository. Try instead creating a unique name, e.g., by adding additional numbers or letters to the target name, such as
mv ~/cop3402spring25/git ~/cop3402spring25/archive/git2
Note that the target is now ~/cop3402spring25/archive/git2
, with an additional git2
at the end, which moves and renames the ~/cop3402spring25/git
directory.
A clever way to generate new names (that are less likely to conflict with an existing name) is to use the RANDOM environment variable, e.g.,
mv ~/cop3402spring25/git ~/cop3402spring25/archive/git.${RANDOM}
8.2. Clone your existing repo
Clone your repo:
git clone gitolite3@eustis3.eecs.ucf.edu:cop3402/$USER/git ~/cop3402spring25/git
Validation
You should see something like the following in the output:
remote: Enumerating objects: 3, done. remote: Counting objects: 100% (3/3), done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 Receiving objects: 100% (3/3), done.
The number of objects may differ depending on your repo's contents.
Errors
- File exists
If you see
fatal: destination path '~/cop3402spring25/git already exists and is not an empty directory.
then you have either forgotten to move your other repo out of the way or have already cloned this repo before. You can just enter
~/cop3402spring25/git
and pull instead, i.e.,cd ~/cop3402spring25/git git pull
- Cloned an empty repo
If you see something like
Initialized empty Git repository in /home/gitolite3/repositories/cop3402/NID/git.git/ warning: You appear to have cloned an empty repository.
then it means you haven't yet pushed your repository yet. Go through the workflow to create your repository. If you still cannot clone it, double-check that you have typed the correct name of the repo.
- Access denied to repo
If you see
FATAL: R any cop3402/ab123546/git ab123456 DENIED by fallthru (or you mis-spelled the reponame) fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
then you may have mistyped your NID. For instance, above it is ab123546, which is supposed to ab123456, i.e., the 4 and 5 are swapped.
- Access denied to eustis3
If you see
Permission denied, please try again.
double-check that you are on eustis.eecs.ucf.edu and not eustis3.eecs.ucf.edu. If your prompt looks like this
NID@eustis3:~$
i.e., it has
eustis3
or if you type the followinghostname
and you see
eustis3
, then you are on the wrong server. Log outexit
then log back into eustis (not eustis3).
8.3. Copy over any material from you old repo
For example, if you want to copy over your latest, uncommitted README.md changes from the origina local repo,
cp ~/cop3402spring25/archive/git/README.md ~/cop3402spring25/git
or use ~/cop3402spring25/git2
or whatever name you used when moving your repo.
There should be no output.
Validation
Enter
git status
You should see (in part of your output) something like
Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: README.md
which reflects the changes to the README.md
that you have copied over. If you don't see this, the the README.md
either is not different from the original repo or you have not committed it yet. In the the latter case, make sure you have completely setup your repo.
Errors
If either directory does not exist, then double-check the names and that they you have followed the previous directions.
9. Grading schema
Criterion | Points |
---|---|
The git repo exists | 3 |
The repo contains README.md | .5 |
There are at least two log entries | .5 |
TOTAL | 4 |
10. Grading script
Log in to eustis and run the following to get the script
mkdir -p ~/grading/cop3402spring25 cd ~/grading/cop3402spring25 wget https://www.cs.ucf.edu/~gazzillo/teaching/cop3402spring25/files/git_grader.sh
Then to grade, run the following, replacing NID
with your UCF NID,
bash git_grader.sh $USER
Note that this grade does not include any late penalty and therefore may differ from your actual grade in webcourses.