Git-Cheatsheet

Kurzanleitung für wichtige Git-Befehle. Durchsuchbares Cheatsheet für Branches, Commits, Merges und mehr.

Team-Entwicklungs-Workflow

In professionellen Umgebungen folgen Teams typischerweise einer Branching-Strategie, bei der jede Aufgabe einen eigenen Branch erhält. Dies isoliert Features und verhindert, dass unfertiger Code die Hauptanwendung beschädigt.

💡

Professionelle Tipps: Streben Sie immer nach kleinen, atomaren Commits. Bevor Sie Ihre Arbeit mergen, verwenden Sie 'git fetch' und dann 'git rebase origin/dev' (oder main), um sicherzustellen, dass Ihr Code mit der neuesten Version kompatibel ist. Verwenden Sie schließlich 'git push -f' auf Ihrem Feature-Branch, um den Remote mit Ihrer rebased Historie zu aktualisieren.

Konfiguration

Globale Konfiguration festlegen

git config --global user.name "[name]" git config --global user.email "[email]"

Konfiguriert Ihre Identität für alle Repositories auf Ihrem System.

Erste Schritte

Git-Repository erstellen

git init

Initialisiert ein neues Git-Repository im aktuellen Verzeichnis.

Vorhandenes Git-Repository klonen

git clone [url]

Kopiert ein vorhandenes Git-Repository von einem Remote-Server.

Commit

Alle verfolgten Änderungen committen

git commit -am "[commit message]"

Staged und committed alle geänderten verfolgten Dateien in einem Befehl.

Neue Änderungen zum letzten Commit hinzufügen

git commit --amend

Aktualisiert den letzten Commit mit aktuellen Änderungen und ändert optional die Nachricht.

Branching

Neuen Branch erstellen

git branch [branch-name]

Erstellt einen neuen Branch am aktuellen Pointer.

Zu einem Branch wechseln

git checkout [branch-name]

Wechselt HEAD zum angegebenen Branch.

Branch in aktuellen Branch mergen

git merge [branch-name]

Kombiniert Historie von einem anderen Branch in Ihren aktuellen.

Branch erstellen und wechseln

git checkout -b [branch-name]

Die häufigste Methode, um mit einem neuen Feature zu beginnen.

Synchronisierung

Updates vom Remote abrufen

git fetch

Lädt Remote-Änderungen herunter, ohne sie zu mergen.

Neueste Änderungen pullen

git pull

Ruft Änderungen ab und versucht sofort, sie zu mergen.

Aktuellen Branch auf Main rebasen

git rebase main

Wiederholt Ihre Commits auf dem neuesten Main-Branch.

Änderungen pushen (Force)

git push -f

Aktualisiert den Remote-Branch mit Ihrer lokalen Historie erzwungen. Nur auf privaten Branches verwenden!

Nützliche Befehle

Status überprüfen

git status

Zeigt an, welche Dateien geändert, staged oder nicht verfolgt sind.

Änderungen stashen

git stash

Versteckt Änderungen vorübergehend, um an etwas anderem zu arbeiten.

Historie anzeigen

git log --oneline --graph --all

Visualisiert die Commit-Historie über alle Branches hinweg.

So verwenden Sie dieses Git-Cheatsheet

  1. Browse the cheatsheet to find the Git command you need.
  2. Commands are organized by category: Configuration, Get Started, Commit, Branching, Syncing, and Useful Commands.
  3. Click the copy button next to any command to copy it to your clipboard.
  4. Paste the command into your terminal and modify the placeholder values as needed.

Advanced Rebasing

Rebasing is often preferred over merging to maintain a clean, linear project history. Instead of creating a 'merge commit', it repositions your commits at the end of the target branch.

Tip

Remember: Never rebase a public branch that others are working on, as it rewrites history and can cause significant conflicts for your peers.

Key Features

  • Essential Git commands organized by workflow category
  • One-click copy for every command
  • Clear descriptions explaining what each command does
  • Covers configuration, branching, syncing, and more
  • Team workflow guidance with professional tips
  • Rebasing best practices and safety warnings
  • Works offline once loaded in your browser

Common Use Cases

  • Quick reference while working in the terminal
  • Onboarding new developers to Git workflows
  • Reviewing branching and merging strategies
  • Learning Git commands for the first time
  • Refreshing memory on less frequently used commands
  • Setting up Git configuration on a new machine

Häufig gestellte Fragen (FAQ)

What is the difference between git merge and git rebase?

Git merge creates a new merge commit that combines two branches, preserving the full history. Git rebase replays your commits on top of the target branch, creating a linear history. Rebase produces a cleaner log but should never be used on shared public branches.

When should I use git stash?

Use git stash when you need to switch branches but have uncommitted changes you are not ready to commit. Stash saves your working directory state temporarily. You can restore it later with 'git stash pop' on any branch.

Is it safe to use git push --force?

Force pushing is safe only on branches that you alone work on, such as personal feature branches. Never force push to shared branches like main or develop, as it rewrites remote history and can cause other team members to lose their work.

Verwandte Tools