Git Befehle / Cheat sheet / Spickzettel



Neuen Branch erstellen und wechselnLink to this section

git switch -c TASK-123

Ältere Variante, funktioniert weiterhin:

git checkout -b TASK-123

Branch wechselnLink to this section

git switch branchname

Ältere Variante: git checkout branchname

Commit mit Kommentar hinzufügenLink to this section

git commit -m '[TASK-123] Kommentar ...'

Git merge (vorher auf main wechseln)Link to this section

git merge --no-ff TASK-123

Branch pushenLink to this section

git push origin TASK-123

Zeige welche Dateien im Branch gegenüber main verändert wurdenLink to this section

git diff --name-status main...TASK-123

Die drei Punkte vergleichen mit dem Stand, an dem der Branch von main abgezweigt wurde. So siehst du nur die Änderungen aus dem Branch.

Git Head zurücksetzenLink to this section

Achtung: --hard verwirft alle nicht committeten Änderungen.

git reset --hard HEAD

Git Remote Branch löschenLink to this section

git push origin --delete BRANCH-123

Kurzform: git push origin :BRANCH-123

Git Local Branch löschenLink to this section

git branch -d BRANCH-123

oder (auch wenn der Branch noch nicht gemergt ist)

git branch -D BRANCH-123

Git Cherry PickLink to this section

git cherry-pick COMMIT-NUMMER

Alle Remote-Branches holen und aktualisierenLink to this section

git fetch --all --prune

Einen Remote-Branch lokal auschecken: git switch branchname legt automatisch einen lokalen Tracking-Branch an, wenn es genau einen Remote-Branch mit diesem Namen gibt.

Falls du wirklich für jeden Remote-Branch einen lokalen Branch anlegen willst:

for remote in $(git branch -r | grep -v -- '->'); do git branch --track "${remote#origin/}" "$remote"; done
Comments 💬 & Reactions ✨