Die Git-Beherrschung unterscheidet Junior-Entwickler von Senior-Entwicklern. Über die grundlegenden Add/Commit/Push-Funktionen hinaus verbessern erweiterte Git-Funktionen – interaktives Rebase, Cherry-Pick, Bisect, Worktrees und Hooks – Ihren Workflow und Ihre Debugging-Funktionen erheblich. Dieser Leitfaden behandelt die erweiterten Git-Funktionen, die jeder Entwickler im Jahr 2026 kennen sollte.
📋 Table of Contents
- Interaktives Rebase – Geschichte neu schreiben
- git Cherry-pick – Spezifische Commits anwenden
- git bisect – Finden Sie den Bug-introducing Commit
- git worktree – Mehrere Arbeitsverzeichnisse
- git reflog – Gelöschte Commits wiederherstellen
- Git Hooks – Workflow automatisieren
- Erweiterte Verwendung von git stash
- Nützliche erweiterte Befehle
- Git-Konfigurationstipps
Interaktives Rebase – Geschichte neu schreiben
# Squash last 5 commits into one
git rebase -i HEAD~5
# Opens editor with:
# pick a1b2c3d feat: add user authentication
# pick b2c3d4e fix: correct email validation
# pick c3d4e5f docs: add API documentation
# pick d4e5f6a test: add auth tests
# pick e5f6a7b chore: update dependencies
# Change to:
# pick a1b2c3d feat: add user authentication
# squash b2c3d4e fix: correct email validation
# squash c3d4e5f docs: add API documentation
# squash d4e5f6a test: add auth tests
# squash e5f6a7b chore: update dependencies
# Result: one clean commit with all changes
# Other rebase commands:
# reword - edit commit message
# edit - pause to amend commit
# drop - delete commit
# fixup - squash but discard commit message
git Cherry-pick – Spezifische Commits anwenden
# Apply a commit from another branch
git cherry-pick a1b2c3d
# Apply a range of commits
git cherry-pick a1b2c3d..e5f6a7b
# Apply but don't commit yet (--no-commit)
git cherry-pick --no-commit a1b2c3d
# Cherry-pick a merge commit
git cherry-pick -m 1 merge_commit_hash
# Common use case: hotfix on main, apply to release branch
git checkout release/1.2
git cherry-pick fix/critical-security-patch
git bisect – Finden Sie den Bug-introducing Commit
# Binary search through commits to find bug introduction
git bisect start
git bisect bad HEAD # current commit has the bug
git bisect good v2.1.0 # this version was fine
# Git checks out a middle commit...
# Test if bug exists, then:
git bisect good # no bug → search upper half
# or
git bisect bad # bug exists → search lower half
# After finding the bad commit:
git bisect reset # return to HEAD
# Automate bisect with a test script
git bisect start
git bisect bad HEAD
git bisect good v2.1.0
git bisect run python test_feature.py # exits 0=good, 1=bad
# Git will tell you: "first bad commit is abc123..."
# Then examine: git show abc123
git worktree – Mehrere Arbeitsverzeichnisse
# Work on two branches simultaneously without stashing
git worktree add ../myapp-hotfix hotfix/critical-bug
# Now you have:
# ./myapp/ — main working tree (current branch)
# ../myapp-hotfix/ — second working tree (hotfix branch)
# Both can run independently:
cd ../myapp-hotfix && python manage.py runserver 8001 &
cd myapp && python manage.py runserver 8000 &
# List worktrees
git worktree list
# Remove worktree when done
git worktree remove ../myapp-hotfix
git reflog – Gelöschte Commits wiederherstellen
# See every action Git has tracked (even resets and deleted commits)
git reflog
# Output:
# a1b2c3d HEAD@{0}: reset: moving to HEAD~1
# b2c3d4e HEAD@{1}: commit: add important feature <-- this was "deleted"
# c3d4e5f HEAD@{2}: commit: initial setup
# Recover a "deleted" commit
git checkout -b recovery-branch HEAD@{1}
# Or reset to a previous state
git reset --hard HEAD@{1}
# Reflog is your safety net — all recent actions are tracked
# Default retention: 90 days for reachable refs, 30 for unreachable
Git Hooks – Workflow automatisieren
# Hooks live in .git/hooks/ (not committed to repo by default)
# Use pre-commit package or Husky for team-shared hooks
# Install pre-commit (Python)
pip install pre-commit
# .pre-commit-config.yaml
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.0
hooks:
- id: ruff # linting
- id: ruff-format # formatting
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.9.0
hooks:
- id: mypy
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: check-yaml
- id: check-json
- id: detect-private-key
# Install hooks
pre-commit install
# Run manually
pre-commit run --all-files
Erweiterte Verwendung von git stash
# Stash with a descriptive name
git stash push -m "WIP: user authentication refactor"
# Stash specific files only
git stash push -m "database changes" -- src/db/models.py src/db/migrations/
# List stashes
git stash list
# stash@{0}: WIP: user authentication refactor
# stash@{1}: database changes
# Apply specific stash (doesn't remove it)
git stash apply stash@{1}
# Pop specific stash (applies and removes)
git stash pop stash@{0}
# Show stash diff
git stash show -p stash@{0}
# Apply stash to different branch
git checkout feature-branch
git stash apply stash@{2}
Nützliche erweiterte Befehle
# git log — powerful filtering
git log --oneline --graph --all # visual branch history
git log --author="Alice" --since="1 week ago"
git log -S "functionName" # find when a string was added/removed
git log -p -- path/to/file # show diffs for a specific file
# git blame — who wrote each line
git blame src/auth.py
git blame -L 100,150 src/auth.py # specific line range
# git diff — compare anything
git diff HEAD~3 HEAD -- file.py # changes in file over last 3 commits
git diff branch1...branch2 # changes in branch2 since branching from branch1
# git show — inspect a commit
git show a1b2c3d
git show a1b2c3d:src/auth.py # show file at that commit
# git grep — search across commits
git grep "TODO" HEAD -- "*.py"
git grep -n "functionName" # with line numbers
# git add -p — stage hunks interactively
git add -p src/models.py # choose which changes to stage
# Clean untracked files
git clean -n # dry run
git clean -fd # remove untracked files and directories
# git shortlog — contributor summary
git shortlog -sn --no-merges | head -10
Git-Konfigurationstipps
# Useful global aliases
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.lg "log --oneline --graph --all --decorate"
git config --global alias.undo "reset HEAD~1 --mixed"
git config --global alias.wip "commit -am 'WIP'"
# Useful defaults
git config --global pull.rebase true # rebase on pull (not merge)
git config --global push.default current # push current branch only
git config --global rerere.enabled true # remember conflict resolutions
git config --global core.autocrlf input # normalize line endings (macOS/Linux)
# Sign commits with GPG
git config --global commit.gpgsign true
git config --global user.signingkey <YOUR_GPG_KEY_ID>
Die Beherrschung von Git erfolgt durch die regelmäßige Nutzung dieser Funktionen und nicht nur durch das Lesen darüber. Fügen Sie interaktives Rebase zu Ihrem PR-Workflow hinzu, verwenden Sie bisect zum Verfolgen von Fehlern und richten Sie Pre-Commit-Hooks für Konsistenz ein. Der Reflog ist Ihr Sicherheitsnetz – fast nichts in Git ist wirklich irreversibel.
🔗 Share this article
✍️ Leave a Comment