Wesentliche Git-Befehle für Commits, Branches, Merges, Rebases, Remotes und mehr.
git config --global user.name "Name"Einrichtung & KonfigurationSet global author name
z.B. git config --global user.name "Jane Doe"
git config --global user.email "email"Einrichtung & KonfigurationSet global author email
z.B. git config --global user.email "[email protected]"
git config --listEinrichtung & KonfigurationList all configuration settings
git config --global core.editor "code"Einrichtung & KonfigurationSet VS Code as default editor
git config --global alias.<alias> <cmd>Einrichtung & KonfigurationCreate a command alias
z.B. git config --global alias.st status
git initEinrichtung & KonfigurationInitialize a new local repository
git init <dir>Einrichtung & KonfigurationInitialize a repo in a specific directory
z.B. git init my-project
git clone <url>Einrichtung & KonfigurationClone a remote repository
z.B. git clone https://github.com/user/repo.git
git clone <url> <dir>Einrichtung & KonfigurationClone into a specific folder
z.B. git clone https://github.com/user/repo.git my-dir
git statusStaging & GrundlagenShow working tree status
git status -sStaging & GrundlagenShort/compact status output
git add <file>Staging & GrundlagenStage a specific file
z.B. git add README.md
git add .Staging & GrundlagenStage all changes in current directory
git add -pStaging & GrundlagenInteractively stage hunks of changes
git commit -m "msg"Staging & GrundlagenCommit staged changes with a message
z.B. git commit -m "feat: add login page"
git commit -am "msg"Staging & GrundlagenStage tracked files and commit in one step
git commit --amenddestruktivStaging & GrundlagenModify the most recent commit (message or content)
git diffStaging & GrundlagenShow unstaged changes
git diff --stagedStaging & GrundlagenShow staged changes (vs last commit)
git diff <branch1>..<branch2>Staging & GrundlagenCompare two branches
z.B. git diff main..feature
git rm <file>Staging & GrundlagenRemove a file from working tree and index
z.B. git rm old-file.txt
git rm --cached <file>Staging & GrundlagenUntrack a file without deleting it
z.B. git rm --cached secret.txt
git mv <old> <new>Staging & GrundlagenMove or rename a tracked file
z.B. git mv old.js new.js
git branchVerzweigung & ZusammenführungList local branches
git branch -aVerzweigung & ZusammenführungList all branches (local + remote)
git branch <name>Verzweigung & ZusammenführungCreate a new branch
z.B. git branch feature/auth
git checkout <branch>Verzweigung & ZusammenführungSwitch to an existing branch
z.B. git checkout main
git checkout -b <branch>Verzweigung & ZusammenführungCreate and switch to a new branch
z.B. git checkout -b feature/auth
git switch <branch>Verzweigung & ZusammenführungSwitch branches (modern syntax)
z.B. git switch main
git switch -c <branch>Verzweigung & ZusammenführungCreate and switch (modern syntax)
z.B. git switch -c feature/auth
git branch -d <branch>Verzweigung & ZusammenführungDelete a merged branch
z.B. git branch -d feature/auth
git branch -D <branch>destruktivVerzweigung & ZusammenführungForce delete a branch (unmerged too)
z.B. git branch -D feature/old
git branch -m <old> <new>Verzweigung & ZusammenführungRename a branch
z.B. git branch -m old-name new-name
git merge <branch>Verzweigung & ZusammenführungMerge a branch into current branch
z.B. git merge feature/auth
git merge --no-ff <branch>Verzweigung & ZusammenführungMerge with a merge commit (no fast-forward)
git merge --squash <branch>Verzweigung & ZusammenführungSquash all commits from branch into one staged change
git merge --abortVerzweigung & ZusammenführungAbort an in-progress merge
git remote -vRemote-OperationenList remote connections with URLs
git remote add <name> <url>Remote-OperationenAdd a new remote
z.B. git remote add origin https://github.com/user/repo.git
git remote remove <name>Remote-OperationenRemove a remote connection
z.B. git remote remove origin
git remote rename <old> <new>Remote-OperationenRename a remote
z.B. git remote rename origin upstream
git fetchRemote-OperationenDownload all changes from remote (no merge)
git fetch <remote>Remote-OperationenFetch from a specific remote
z.B. git fetch origin
git pullRemote-OperationenFetch and merge changes from remote
git pull --rebaseRemote-OperationenFetch and rebase onto remote branch
git push <remote> <branch>Remote-OperationenPush branch to remote
z.B. git push origin main
git push -u origin <branch>Remote-OperationenPush and set upstream tracking
z.B. git push -u origin feature/auth
git push --force-with-leasedestruktivRemote-OperationenSafe force push (fails if others pushed)
git push --tagsRemote-OperationenPush all tags to remote
git push origin --delete <branch>destruktivRemote-OperationenDelete a remote branch
z.B. git push origin --delete feature/old
git restore <file>destruktivÄnderungen rückgängig machenDiscard changes in working directory
z.B. git restore index.html
git restore --staged <file>Änderungen rückgängig machenUnstage a file (keep changes)
z.B. git restore --staged index.html
git reset HEAD <file>Änderungen rückgängig machenUnstage a file (older syntax)
z.B. git reset HEAD index.html
git reset --soft HEAD~1Änderungen rückgängig machenUndo last commit, keep changes staged
git reset --mixed HEAD~1Änderungen rückgängig machenUndo last commit, unstage changes (default)
git reset --hard HEAD~1destruktivÄnderungen rückgängig machenUndo last commit, discard all changes
git reset --hard <commit>destruktivÄnderungen rückgängig machenReset to a specific commit, discard everything after
git revert <commit>Änderungen rückgängig machenCreate a new commit that undoes a specific commit
z.B. git revert a1b2c3d
git revert HEADÄnderungen rückgängig machenRevert the most recent commit
git clean -fddestruktivÄnderungen rückgängig machenRemove untracked files and directories
git clean -nÄnderungen rückgängig machenDry run: show what would be cleaned
git stashStashenStash current working directory changes
git stash push -m "msg"StashenStash with a descriptive message
z.B. git stash push -m "WIP: auth feature"
git stash listStashenList all stashes
git stash popStashenApply most recent stash and remove it
git stash apply stash@{n}StashenApply a specific stash without removing
z.B. git stash apply stash@{0}
git stash drop stash@{n}StashenDelete a specific stash
z.B. git stash drop stash@{0}
git stash cleardestruktivStashenRemove all stashes
git stash branch <branch>StashenCreate a branch from a stash
z.B. git stash branch feature/from-stash
git rebase <branch>Rebase & FortgeschrittenRebase current branch onto another
z.B. git rebase main
git rebase -i HEAD~nRebase & FortgeschrittenInteractive rebase for last n commits
z.B. git rebase -i HEAD~3
git rebase --continueRebase & FortgeschrittenContinue rebase after resolving conflicts
git rebase --abortRebase & FortgeschrittenAbort an in-progress rebase
git cherry-pick <commit>Rebase & FortgeschrittenApply a specific commit to current branch
z.B. git cherry-pick a1b2c3d
git cherry-pick <c1>..<c2>Rebase & FortgeschrittenApply a range of commits
z.B. git cherry-pick a1b2c3d..f6e5d4c
git bisect startRebase & FortgeschrittenStart binary search for a bug
git bisect good <commit>Rebase & FortgeschrittenMark a commit as good in bisect
git bisect bad <commit>Rebase & FortgeschrittenMark a commit as bad in bisect
git bisect resetRebase & FortgeschrittenEnd bisect session
git worktree add <path> <branch>Rebase & FortgeschrittenCheck out a branch into a separate directory
git logInspektion & LogShow commit history
git log --onelineInspektion & LogCompact one-line log
git log --oneline --graph --allInspektion & LogVisual branch graph in terminal
git log -n <count>Inspektion & LogShow last N commits
z.B. git log -n 5
git log --author="name"Inspektion & LogFilter commits by author
z.B. git log --author="Jane Doe"
git log --since="2 weeks ago"Inspektion & LogShow commits since a date
git log -p <file>Inspektion & LogShow changes to a specific file over time
z.B. git log -p README.md
git log --follow <file>Inspektion & LogFollow renames of a file in history
git show <commit>Inspektion & LogShow details of a specific commit
z.B. git show a1b2c3d
git blame <file>Inspektion & LogShow who last modified each line
z.B. git blame src/app.tsx
git shortlog -snInspektion & LogSummarize commits by author
git reflogInspektion & LogShow history of HEAD movements (recovery tool)
git grep "pattern"Inspektion & LogSearch working directory for a pattern
z.B. git grep "TODO"
git tagTagsList all tags
git tag <name>TagsCreate a lightweight tag
z.B. git tag v1.0.0
git tag -a <name> -m "msg"TagsCreate an annotated tag
z.B. git tag -a v1.0.0 -m "Release v1.0.0"
git tag -a <name> <commit>TagsTag a past commit
z.B. git tag -a v0.9.0 a1b2c3d
git show <tag>TagsShow tag metadata and commit
z.B. git show v1.0.0
git push origin <tag>TagsPush a specific tag to remote
z.B. git push origin v1.0.0
git push origin --tagsTagsPush all tags to remote
git tag -d <tag>TagsDelete a local tag
z.B. git tag -d v1.0.0
git push origin --delete <tag>TagsDelete a remote tag
z.B. git push origin --delete v1.0.0
git merge kombiniert zwei Branches durch Erstellung eines Merge-Commits und bewahrt die vollständige Geschichte beider Branches. git rebase verschiebt Commits von einem Branch auf einen anderen und schreibt die Geschichte um, um eine lineare, sauberere Commit-Historie zu erstellen. Verwenden Sie merge für öffentliche Branches und geteilte Arbeit; rebase zum Bereinigen lokaler Feature-Branches vor dem Mergen.
Verwenden Sie git reset --soft HEAD~1, um den letzten Commit rückgängig zu machen, während Änderungen gestaged bleiben. Verwenden Sie git reset HEAD~1 (oder --mixed), um Änderungen zu entstagen, aber im Arbeitsverzeichnis zu behalten. Verwenden Sie git reset --hard HEAD~1, um den Commit und alle Änderungen dauerhaft zu verwerfen (destruktive Operation).
git fetch lädt Änderungen vom Remote herunter, führt sie aber NICHT in Ihren aktuellen Branch zusammen. Es aktualisiert Ihre Remote-Tracking-Branches (origin/main). git pull ist git fetch + git merge (oder git rebase mit --rebase Flag). Verwenden Sie fetch, wenn Sie Änderungen vor der Integration prüfen möchten.
Nach einem konfliktbehafteten Merge/Rebase markiert Git konflikte Dateien mit '<<<<<<', =======, >>>>>> Markierungen. Öffnen Sie jede konfliktbehaftete Datei, wählen Sie manuell welche Änderungen behalten werden sollen, entfernen Sie die Markierungen, fügen Sie die gelösten Dateien mit git add '<'datei> hinzu und schließen Sie mit git merge --continue oder git commit ab.