Files

1.9 KiB
Raw Permalink Blame History

Lösung Aufgabe 03: Branches

Schau dir diese Lösung erst an, nachdem du die Aufgabe selbst versucht hast!


Schritt-für-Schritt-Lösung

1. Ausgangssituation herstellen

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

git switch -c feature/begruessung
Switched to a new branch 'feature/begruessung'

3. Datei erstellen und committen

echo "Hallo, Welt!" > hallo.txt
echo "Willkommen in meinem ersten Git-Projekt." >> hallo.txt
git add hallo.txt
git commit -m "feat: Begrüßungsdatei hinzugefügt"
[feature/begruessung c3d4e56] feat: Begrüßungsdatei hinzugefügt
 1 file changed, 2 insertions(+)
 create mode 100644 hallo.txt

4. Zurück zu main

git switch main
Switched to branch 'main'

Prüfe, ob hallo.txt da ist:

ls
README.md

hallo.txt fehlt korrekt! Auf main existiert sie noch nicht.

5. Commit-Übersicht beider Branches

git log --all --oneline --graph
* c3d4e56 (feature/begruessung) feat: Begrüßungsdatei hinzugefügt
* a1b2c3d (HEAD -> main) chore: Projekt angelegt

6. Merge

git merge feature/begruessung
Updating a1b2c3d..c3d4e56
Fast-forward
 hallo.txt | 2 ++
 1 file changed, 2 insertions(+)
 create mode 100644 hallo.txt

hallo.txt ist jetzt auf main vorhanden.

7. Branch aufräumen

git branch -d feature/begruessung
Deleted branch feature/begruessung (was c3d4e56).

Abschlusszustand

git log --oneline
c3d4e56 (HEAD -> main) feat: Begrüßungsdatei hinzugefügt
a1b2c3d chore: Projekt angelegt
git branch
* main

Zurück zur Aufgabe