Git and GitLab

IT1901 Fall 2020 - 14th Lecture

Overview

  • Git

    • basic workflow recap

    • working with branches

    • code review

  • GitLab

    • Issues

    • Milestones

    • Merge requests

    • Issues / MR Templates

Basic workflow

  • work on main branch (master)

  • could be usable for individual / very small teams

  • prone to conflicts

Typical sequence (basic)

  • working with a shared project

    • git clone

    • git pull

  • git status

  • git add …​

  • git commit …​

  • git push

Conflicts (1)

  • when same files (lines) are changed by different devs

  • automatic merge is not possible

  • we need to solve that to be able to push our changes

Conflicts (2) - Setup

  • git config merge.tool vimdiff

  • git config merge.conflictstyle diff3

  • git config mergetool.prompt false

Conflicts (3) - Solving

  • git mergetool

  • :wqa save and exit from vi

  • git commit -m "message"

  • git clean remove file (might remove other untracked files)

Conflicts (4)

  • one can plan ahead what issues should be worked on in parralel to minimize the chance of conflicts

  • when working on a feature branch, keeping up to date with relevant branches (master or other branch we depend upon) can reduce the risk of getting conflicts

Improved workflow

  • keep master only for finished work

  • uses branches for development work

  • when a feature branch is done it is merged into master

Typical sequence (branches)

  • git clone

  • git pull

  • git checkout -b <branch_name>

  • git status + git add …​ + git commit …​

  • git checkout master

  • git merge <branch_name>

  • git push

Improved workflow (code review)

  • keep master only for finished work

  • uses branches for development work

  • when a feature branch is done a merge request is created

  • code review takes place and more commits happen to address the comments

  • the branch is finally merged into master

Gitlab specific push options

  • push options

-o merge_request.create
-o merge_request.target=my-target-branch
-o merge_request.label="Label with spaces"

Advanced workflow (git flow)

Gitlab for agile

  • Issues

  • Milestones

  • Task lists

  • Labels

  • Boards

  • Quick actions

Using templates

  • Issue templates

  • Merge request templates

Summary

Norwegian University of Science and Technology