Workshop - GIT branches

Ugeplan

Dag Emne
Mandag 8.30 - 11.45 Klasseundervisning og igangsætning af Sprint #1
Tirsdag Vejledning med tutorer
Onsdag Review (vejledning med underviser)
Torsdag Sprint #1 Review - Sprint #1 Retrospektive - Sprint #2 Planning
Fredag Store Bededag (fri)

Læringsmål

Erhvervskompetencer

Baggrundsmateriale

Grundliggende brug af GIT

For de som trænger til en sammenhængende gennemgang af de grundliggende kommandoer i GIT, har vi samlet en side med instruktioner og øvelser.

Dagens workshop-tema: Branching and merging i GIT

Vi anbefaler, at de enkelte Scrum-teams anvender følgende GIT-workflow:

Formålet med dagens workshop i GIT er, at få praktisk erfaring med brug af netop Git Feature Branch Workflow. På Atlassians hjemmeside findes en grundig gennemgang: Git Feature Branch Workflow

Branches checklist (what you should know at the end of the workshop):

  1. Create branches
  2. Merge branches
  3. Feature branch workflow
  4. Merge branches with rebase
  5. Forking a project vs. branching
  6. Making a pull request
    • Using git issues
    • Labels and notifications

What are branches?

Why would we need branches?

How should i branch

Create new branches

Push branch to upstream

Branches are easy to move around and often refer to different commits as work is completed on them. Branches are easily mutated, often temporary, and always changing.

Changing branch

IMPORTANT:

Lets demo

Demonstrate creating branches and commits in each branch

Small individual class exercise

  1. Create 3 branches
  2. Check them out individually and add a file and commit in each branch
  3. run: git log --oneline --decorate --graph --all to see how your git branches look now
  4. create an alias so that you can run the command in this prevous line by just writing git graf.

Small exercise in pairs (master - development branches)

Work in pairs to:

Merging and deleting branch

Quit merging:

Fast-Forward merge

Three way merge

The image shows how iss53 branch is merged into master with three-way-merge using C5+C4 and their common ancestor C2 to create a new merge commmit: C6 which master will then point to (and now iss53 can be deleted)

Merge conflicts

When you git merge and it creates a CONFLICT do git status and it tells what to do

Lets demo

Merge conflicts

  1. create a new repo
  2. make some files - add - commit
  3. Create a new branch
  4. In each branch master and mybranch change the text file (one: deletes a line and two: change the line)
  5. Commit each branch
  6. Merge mybranch into master
  7. git status
  8. Look inside the file and see how to solve the conflict
  9. Solve the conflict and commit.

Small exercise

  1. Create a new git repo
  2. Add a text file to the repo and run: git add . and git commit -m "initial commit"
  3. checkout a new branch: feature1
  4. do some changes to the text file - save - git add - git commit
  5. checkout a new branch: feature2
  6. do some changes to the text file - save - git add - git commit
  7. merge the two branches and resolve conflict

Rebase

Advanced GIT commands and practices

These are not necessary for most teams, but nice to know.

Changing (moving commits) in existing branches

This is advanced stuff, and is best practiced through this interactive exercise

Small exercise manipulating branches

  1. create a git repo
  2. make 3 commits in master
  3. make 2 new branches: development, feature1
  4. create 3 commits in both development and feature1 (files need to be created or changed in each commit)
  5. Move feature1 to the head of development

Git issues

Git milestones

Git issues - labels

Small exercise with issues, milestones and labels

  1. In the last repo you created
  2. create 3 milestones
  3. Create 2 label: ‘new feature’ and ‘java servlet’
  4. create 3 isssues and tag them with labels and milestones
  5. add Assignees to each issue

Git forking

Git pull request

pull requests are a mechanism for a developer to notify team members that they have completed a feature. Once their feature branch is ready, the developer files a pull request

Extra exercises for the dedicated

The exercise is here