Git Cheat Sheet
Searchable reference for 100+ git commands — setup, branching, merging, stashing, rebasing, remotes, and advanced tips with one-click copy
git config --global user.name "Name"Set global username
git config --global user.email "email"Set global email
git config --global core.editor "code"Set default editor (VS Code)
git config --listList all config settings
git config --global alias.st statusCreate a git alias (st → status)
git config --global color.ui autoEnable colorized output
git initInitialize a new local repository
git init <directory>Init in a specific folder
git clone <url>Clone a remote repository
git clone <url> <directory>Clone into a specific folder
git clone --depth 1 <url>Shallow clone (latest commit only)
git clone -b <branch> <url>Clone a specific branch
git statusShow working tree status
git add <file>Stage a specific file
git add .Stage all changes in current dir
git add -pInteractively stage chunks (hunks)
git commit -m "message"Commit staged changes with message
git commit -am "message"Stage tracked files and commit
git commit --amendModify the last commit
git commit --amend --no-editAmend last commit without changing message
git commit --allow-empty -m "msg"Create a commit with no changes
git branchList all local branches
git branch -aList all local and remote branches
git branch <name>Create a new branch
git branch -d <name>Delete a branch (safe)
git branch -D <name>Force-delete a branch
git branch -m <old> <new>Rename a branch
git checkout <branch>Switch to an existing branch
git checkout -b <branch>Create and switch to a new branch
git switch <branch>Switch branch (modern syntax)
git switch -c <branch>Create and switch (modern syntax)
git merge <branch>Merge a branch into current
git merge --no-ff <branch>Merge with a merge commit (no fast-forward)
git merge --squash <branch>Squash all commits into one before merging
git merge --abortAbort an in-progress merge
git rebase <branch>Rebase current branch onto another
git rebase -i HEAD~3Interactive rebase last 3 commits
Squash, reorder, or edit recent commits
git rebase --continueContinue after resolving conflicts
git rebase --abortAbort rebase and return to original state
git cherry-pick <commit>Apply a specific commit to current branch
git cherry-pick <c1>..<c2>Cherry-pick a range of commits
git remote -vList remotes with URLs
git remote add origin <url>Add a remote named origin
git remote rename origin upstreamRename a remote
git remote remove <name>Remove a remote
git remote set-url origin <url>Change a remote URL
git fetchFetch all remotes
git fetch <remote>Fetch from a specific remote
git pullFetch and merge from tracking branch
git pull --rebaseFetch and rebase instead of merge
git push origin <branch>Push branch to remote
git push -u origin <branch>Push and set upstream tracking
git push --force-with-leaseSafe force-push (won't overwrite others' work)
git push origin --delete <branch>Delete a remote branch
git logShow commit history
git log --onelineCompact one-line log
git log --oneline --graph --allVisual branch graph
git log -pShow diffs with each commit
git log --author="name"Filter commits by author
git log --since="2 weeks ago"Filter commits by date
git log -- <file>Show history for a specific file
git show <commit>Show details of a commit
git diffShow unstaged changes
git diff --stagedShow staged changes
git diff <branch1>..<branch2>Diff between two branches
git blame <file>Show who changed each line
git shortlog -snSummarize commits per author
git restore <file>Discard unstaged changes in a file
git restore --staged <file>Unstage a file (keep changes)
git revert <commit>Create a new commit that undoes another
git reset HEAD~1Undo last commit, keep changes staged
git reset --soft HEAD~1Undo last commit, keep changes in working tree
git reset --hard HEAD~1Undo last commit and discard all changes
⚠️ Destructive — cannot be undone
git reset --hard origin/mainReset local branch to match remote
git clean -fdRemove untracked files and directories
git clean -nDry-run: show what clean would remove
git stashStash current changes
git stash push -m "message"Stash with a description
git stash listList all stashes
git stash popApply latest stash and remove it
git stash apply stash@{2}Apply a specific stash (keep it)
git stash drop stash@{0}Delete a specific stash
git stash clearRemove all stashes
git stash branch <branch>Create a branch from stash
git tagList all tags
git tag <name>Create a lightweight tag
git tag -a v1.0.0 -m "Release"Create an annotated tag
git tag -a v1.0.0 <commit>Tag a specific commit
git push origin <tag>Push a tag to remote
git push origin --tagsPush all tags to remote
git tag -d <tag>Delete a local tag
git push origin --delete <tag>Delete a remote tag
git bisect startStart binary search for a bad commit
git bisect badMark current commit as bad
git bisect good <commit>Mark a known-good commit
git bisect resetEnd bisect session
git reflogShow history of HEAD movements (recovery tool)
git reflog expire --expire=now --allExpire all reflog entries
git gc --prune=nowClean up and optimize repository
git submodule add <url>Add a submodule
git submodule update --init --recursiveInitialize all submodules
git archive --format=zip HEAD > out.zipExport latest commit as ZIP
git grep "pattern"Search for pattern in tracked files
git log --all --full-history -- "**/file"Find a deleted file in history
git worktree add <path> <branch>Check out a branch in a separate directory
*.logIgnore all .log files
node_modules/Ignore node_modules directory
!important.logUn-ignore a specific file (exception)
/distIgnore dist only in root directory
**/__pycache__/Ignore __pycache__ in any directory
git check-ignore -v <file>Debug why a file is ignored
git rm -r --cached .Clear git cache (reapply .gitignore)
112 git commands · hover any command to copy
Weiter entdecken
Weitere Entwickler-Tools, die Ihnen gefallen könnten…
JSON-Formatierer
JSON mit Syntaxhervorhebung und Fehlererkennung formatieren, validieren und minifizieren
Base64 Encoder/Decoder
Text oder Dateien nach Base64 kodieren und Base64-Strings in lesbaren Text dekodieren
URL Encoder/Decoder
URL-Komponenten und Query-String-Parameter kodieren und dekodieren
UUID-Generator
Zufällige UUIDs (v1, v4) generieren oder mehrere UUIDs in Bulk erstellen
Hash-Generator
MD5-, SHA-1-, SHA-256-, SHA-512-Hashes aus Text oder Dateien generieren
Regex-Tester
Reguläre Ausdrücke mit Echtzeit-Übereinstimmungshervorhebung testen
JWT-Decoder
JSON Web Tokens dekodieren und prüfen — Header, Payload und Signaturen ansehen
HTML-Formatierer
HTML-Code mit korrekter Einrückung und Syntaxhervorhebung formatieren