Submission and git Instructions
Table of Contents
Forking Repositories and Submitting Assignments
All assignments for this class will be based around git repositories. The workflow of an assignment will be:
- You fork the repository in gitlab
- Clone you fork to your local directory
- Work and complete the assignment and commit any changes locally
- Once you finish, creating a branch named "submit" which will be your submission
- Push your submit branch to gitlab where I will have access
Forking a repository
First you must find a repository to clone, from your welcome screen, click browse button to view available projects. These will propagate as assignments are assigned throughout the semester.
One the next screen, you may need to select the buttom "show all projects," after which you will see a list of public projects. (Note: No project you create/own should ever be set for public or internal viewing).
Click on a project your interested in, which in this case will be the sample assignment. On the project page you may see some information about the project, but most importantly in the upper right corner is the fork button:
Go ahead and click fork, and then click on your username. Now, you have a version of the project that is all yours.
Cloning the repository to your local machine
To work on the project, you'll need to clone the repository to your local machine. If you look on you newly forked projects dashboard you'll see a URL for your ssh cloning:
Copy that link to the terminal on your local VM where you wish to work and issue the git clone command:
m169999@si485H-saddleback:~$ git clone [email protected]:m169999/sample-assignment.git Cloning into 'sample-assignment'... Ubuntu 14.04.2 LTS remote: Counting objects: 3, done. remote: Total 3 (delta 0), reused 0 (delta 0) Receiving objects: 100% (3/3), done. Checking connectivity... done.
In the current directory, you'll see a directory for the repository and any files:
169999@si485H-saddleback:~$ ls sample-assignment m169999@si485H-saddleback:~$ cd sample-assignment/ m169999@si485H-saddleback:~/sample-assignment$ ls test-file.txt
Add, Commit, Push, Pull
Now that you have a version of the assignment to work, go ahead and do that. But, you might want to save your work along the way. To do that, you'll need to commit your changes locally, and then push those changes to the remote repository on gitlab and pull any changes from remote repository.
For example, consider the situation where you need to edit the test file by adding a line to the end:
m169999@si485H-saddleback:~/sample-assignment$ echo "Hello World" >> test-file.txt m169999@si485H-saddleback:~/sample-assignment$ cat test-file.txt This is a test file Hello World
The test file is a tracked file, which means that changes to it are currently being tracked by git. You can see this using the status command:
m169999@si485H-saddleback:~/sample-assignment$ git status On branch master Your branch is up-to-date with 'origin/master'. Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: test-file.txt no changes added to commit (use "git add" and/or "git commit -a")
To add these changes to the repository, we need to do an add:
m169999@si485H-saddleback:~/sample-assignment$ git add test-file.txt m169999@si485H-saddleback:~/sample-assignment$ git status On branch master Your branch is up-to-date with 'origin/master'. Changes to be committed: (use "git reset HEAD <file>..." to unstage) modified: test-file.txt
And now it is clear that these changes are staged for commit, so we can do so with a commit message.
m169999@si485H-saddleback:~/sample-assignment$ git commit -m "updating test file" [master 77574db] updating test file 1 file changed, 1 insertion(+)
At this point, the local changes are committed to the local repository. However, these changes are not merged with remote repository at gitlab. For that, we must push the changes to origin.
m169999@si485H-saddleback:~/sample-assignment$ git push origin master Ubuntu 14.04.2 LTS Counting objects: 5, done. Writing objects: 100% (3/3), 289 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To [email protected]:m169999/sample-assignment.git fba00fc..77574db master -> master
The phrase "origin master" refers to the origin repository, the one you cloned from gitlab for the master branch. That is the primary branch for all repositories. When you do a submit, you'll create a new branch that you'll push to the origin to indicate you've completed the assignment.
(Note: adding new files to the repository are the same as editting tracked files, just use the add command to have them tracked, and the commit and push)
Creating a new branch and submitting
Let's suppose you've completed the assignment and now you want to submit. To submit, you must create a new branch of the master with the name "submit". This is quite simple:
m169999@si485H-saddleback:~/sample-assignment$ git branch submit
This will create a "local copy" of all the files tracked separately from the master branch. You can see all the branches by just using branch:
m169999@si485H-saddleback:~/sample-assignment$ git branch * master submit
And you can see that we are still on the master branch. If we wish to edit the other branch we have to "checkout" the new branch:
m169999@si485H-saddleback:~/sample-assignment$ git checkout submit Switched to branch 'submit' m169999@si485H-saddleback:~/sample-assignment$ git branch master * submit
Now any changes you make will be tracked on the submit branch not the master. Since you should only be branching at the very end for submitting, you shouldn't need to checkout a branch other than the master; however, as you get better at using git, you might want to do some more advanced things, so it is good to know this information. So let's go back to the master branch:
m169999@si485H-saddleback:~/sample-assignment$ git checkout master Switched to branch 'master' Your branch is up-to-date with 'origin/master'. m169999@si485H-saddleback:~/sample-assignment$ git branch * master submit
Now, to submit, we must push the submit branch to the origin, namely gitlab:
m169999@si485H-saddleback:~/sample-assignment$ git push origin submit Ubuntu 14.04.2 LTS Total 0 (delta 0), reused 0 (delta 0) To [email protected]:m169999/sample-assignment.git * [new branch] submit -> submit
While you've pushed the submit branch and you can check that the branch exists in gitlab website by clicking on the "commits" information for the project:
And under the branches tab, you'll see that there is a submit branch.
The last step in a submission (DO NOT FORGET)
HOWEVER YOU HAVE NOT OFFICIALLY SUBMITTED UNTIL YOU ADD ME AS A MEMBER OF THE PROJECT. To do that select members and add members to your project:
Then select my user name and give me reporter access
Now, you have submitted your assignment. You can keep updating the submit branch if you like, and per the course policy, I will reassess all the submission at each assessment date.