Git Exercises (non-credit)
Here are a couple of simple exercises for students to refresh their knowledge of Gitlab. If you are comfortable with your git skills, you don't need to do it.
We will do a three-part exercise, create a git repo; update and commit changes to existing files; and branch and merge a section of code which must go through a code review by a teammate before final commit.
- Create a git repo for CSCI 479. Add one or two of your classmates as the team developer (you can add your instructor if you'd want.) You may follow the instructions for Exercises 1-4 in Lab 01 of CSCI 206 to accomplish this task. Change the names of the project appropriate. For the consistency of this description, we name the project csci479. You should have a directory structure in your Linux account (or on your personal laptop) as csci479/git-exercises/. That is, under the project of csci479 you create a git-exercises directory (folder), similar to the Lab directory for your csci206 directory.
- Create a simple Python program named
hello-world.py
under the directory git-exercises.
You should change the name of the author to yours.
- Save, commit, and push exercises should follow. Once the program is correct, add and commit it to the repo by the following git commands.
Fix any problems before proceeding.
git add hello-world.py
git commit -m "Git exercise"
git push
- Branch, merge, request, and issues allow programming teams to share and review code. Try the following.
- Check out a branch of code so you can work without effecting the main repository. In your current repository at the Linux command line, do
git checkout -b my-branch
You can use any other name for your branch.
- Now that you are in your branch, make some revision in your code. For example, add a line of comment to hello-world.py as
'''Added a line at 11:31 am 2019-09-03'''
- Do the following to save and commit the changes in your branch.
git add .
git commit -m "Made first revision on a branch"
git push
- If this is the first time you check out a branch, you may need to set it up, follow the git error message (suggestion). Most likely you'd need to issue the following git command instead of the one above. You only need to do this once.
git push --set-upstream origin my-branch
- Once a branch is created and revision pushed, you can go into the gitlab window and request a merge and request an issue so someone else on your team can review and respond.
- In the github window, you now should see the project has two branches, master and my-branch (or whatever the name you picked for your branch.) At this point, you, as the one created the my-branch can request a teammate to review and merge your branch. Do the following.
- Locate the new branch you created in the window.
- Click the
Merge request
button to request a merge.- Fill in the title for the request. Write a brief description. Most importantly, choose an Assignee who you'd like to review the code and merge the branch into the master.
- Click the
Submit request
button at the bottom of the window.
- Your teammate, when they open the github window, will see the merge request. They can do one of the two things.
- Merge the branch into the master with some comments. Or
- create an Issue to be reviewed by the original request, possibly revise the branch my-branch and re-submit the merge request. Similar to a merge request, one can designate a reviewer for an Issue.
Resources
- Issues, Merge Requests and Integration in GitLab. Accessed 2019-09-03.
- Exercise: Git and GitLab, especially Step 3: Step 3: Following a Workflow and Code Review. Accessed 2019-09-03.
- Git Branching - Basic Branching and Merging. Accessed 2019-09-03.
- Code Review Via GitLab Merge Requests. Accessed 2019-09-03.
- Gitlab - Create Issues. Accessed 2019-09-03.