Files
Git-Schulung/03-branches/aufgabe.md
T

86 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 📝 Aufgabe 03 Branches
Arbeite die folgenden Schritte durch. Schau erst in die [Lösung](../loesungen/03-loesung.md), wenn du nicht weiterkommst.
---
## Aufgabe
### 1. Ausgangssituation
Nimm das Repo aus Aufgabe 02 (`meine-notizen`) oder lege ein frisches Repo an:
```bash
mkdir branch-uebung
cd branch-uebung
git init
echo "# Branch-Übung" > README.md
git add README.md
git commit -m "chore: Projekt angelegt"
```
### 2. Feature-Branch anlegen
Erstelle einen neuen Branch namens `feature/begruessung` und wechsle direkt dorthin:
```bash
git switch -c feature/begruessung
```
### 3. Neue Datei auf dem Feature-Branch
Erstelle eine Datei `hallo.txt` mit folgendem Inhalt:
```text
Hallo, Welt!
Willkommen in meinem ersten Git-Projekt.
```
Füge die Datei hinzu und committe sie.
### 4. Zurück zu main
Wechsle zurück zu `main`:
```bash
git switch main
```
Schau dir den Ordner an `hallo.txt` ist **nicht da**! Das ist korrekt: auf `main` existiert sie noch nicht.
### 5. Unterschied sehen
Zeige die Commit-Historie beider Branches:
```bash
git log --all --oneline --graph
```
### 6. Feature-Branch mergen
Merge `feature/begruessung` in `main`:
```bash
git merge feature/begruessung
```
Jetzt ist `hallo.txt` auch auf `main` vorhanden.
### 7. Branch aufräumen
Lösche den Feature-Branch, da er nicht mehr gebraucht wird:
```bash
git branch -d feature/begruessung
```
---
## ✅ Erfolgskriterien
- [ ] `git switch -c feature/begruessung` hat einen neuen Branch erstellt
- [ ] `hallo.txt` existiert auf `feature/begruessung`, aber **nicht** auf `main` (vor dem Merge)
- [ ] `git log --all --oneline --graph` zeigt beide Branches
- [ ] Nach dem Merge ist `hallo.txt` auf `main` vorhanden
- [ ] `git branch` zeigt nur noch `main` (nach dem Löschen)