Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

Hoofdstuk 3Naam in de cursus: Git branching

Work in branches and merge them

A branch is a movable name for a line of commits. Work on a change in its own branch, keep main always working, then merge the branch back. Branches are cheap in Git — use one for every change.

  • 4 Lessen
  • 2 Commando's

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

$ als gewone gebruiker# als root (of met sudo)

3.1

Create and switch branches

git switch -c NAME makes a new branch from where you are and moves to it.

git branch
* main
git switch -c feature/web-subnet
git branch -v
git switch main
git switch -
git branch -m feature/web-subnet feature/web-network
CommandDoes
git branchList local branches (-a also remote ones)
git switch -c NAMECreate and switch
git switch NAMESwitch
git branch -m OLD NEWRename
git branch -d NAME / -DDelete (merged / even when not merged)

Onthoud

Name branches by purpose: feature/…, fix/…, docs/….

Commando's in deze les

3.2

Merge a branch

git merge BRANCH brings the commits of BRANCH into the current branch.

git switch main
git merge feature/web-network
git merge --no-ff feature/web-network -m "Merge web network"
git branch -d feature/web-network
Merge typeWhenResult
Fast-forwardmain has no new commitsmain just moves forward
Three-way mergeBoth branches have new commitsA merge commit with two parents
--no-ffYou want a merge commit anywayHistory shows the feature as a group
--squashYou want one commit for the whole featureOne new commit, branch history not kept

Commando's in deze les

3.3

Solve merge conflicts

When both branches changed the same lines, Git stops and marks the conflict in the file. You choose the result.

variables.tf (during a conflict)
<<<<<<< HEAD
default = "Standard_B2s"
=======
default = "Standard_D2s_v5"
>>>>>>> feature/bigger-vm
git status
vim variables.tf
git add variables.tf
git commit
git merge --abort
git checkout --theirs variables.tf

Op het werk

Small, short-lived branches give few conflicts. Merge main into a long branch often, or rebase it.

3.4

Keep main safe

main should always work. Changes go in through pull requests with checks — see Work with GitHub pull requests.

Commando's in deze les

Alle commando's in dit hoofdstuk