Entwickler-Tools

Git Cheat Sheet

Searchable reference for 100+ git commands — setup, branching, merging, stashing, rebasing, remotes, and advanced tips with one-click copy

Setup & Config6Initialize & Clone6Staging & Committing9Branching10Merging & Rebasing10Remote Repositories13Inspecting & Logging13Undoing Changes9Stashing8Tagging8Advanced & Power Tips13.gitignore7
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 --list

List all config settings

git config --global alias.st status

Create a git alias (st → status)

git config --global color.ui auto

Enable colorized output

git init

Initialize 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 status

Show working tree status

git add <file>

Stage a specific file

git add .

Stage all changes in current dir

git add -p

Interactively stage chunks (hunks)

git commit -m "message"

Commit staged changes with message

git commit -am "message"

Stage tracked files and commit

git commit --amend

Modify the last commit

git commit --amend --no-edit

Amend last commit without changing message

git commit --allow-empty -m "msg"

Create a commit with no changes

git branch

List all local branches

git branch -a

List 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 --abort

Abort an in-progress merge

git rebase <branch>

Rebase current branch onto another

git rebase -i HEAD~3

Interactive rebase last 3 commits

Squash, reorder, or edit recent commits

git rebase --continue

Continue after resolving conflicts

git rebase --abort

Abort 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 -v

List remotes with URLs

git remote add origin <url>

Add a remote named origin

git remote rename origin upstream

Rename a remote

git remote remove <name>

Remove a remote

git remote set-url origin <url>

Change a remote URL

git fetch

Fetch all remotes

git fetch <remote>

Fetch from a specific remote

git pull

Fetch and merge from tracking branch

git pull --rebase

Fetch 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-lease

Safe force-push (won't overwrite others' work)

git push origin --delete <branch>

Delete a remote branch

git log

Show commit history

git log --oneline

Compact one-line log

git log --oneline --graph --all

Visual branch graph

git log -p

Show 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 diff

Show unstaged changes

git diff --staged

Show staged changes

git diff <branch1>..<branch2>

Diff between two branches

git blame <file>

Show who changed each line

git shortlog -sn

Summarize 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~1

Undo last commit, keep changes staged

git reset --soft HEAD~1

Undo last commit, keep changes in working tree

git reset --hard HEAD~1

Undo last commit and discard all changes

⚠️ Destructive — cannot be undone

git reset --hard origin/main

Reset local branch to match remote

git clean -fd

Remove untracked files and directories

git clean -n

Dry-run: show what clean would remove

git stash

Stash current changes

git stash push -m "message"

Stash with a description

git stash list

List all stashes

git stash pop

Apply 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 clear

Remove all stashes

git stash branch <branch>

Create a branch from stash

git tag

List 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 --tags

Push all tags to remote

git tag -d <tag>

Delete a local tag

git push origin --delete <tag>

Delete a remote tag

git bisect start

Start binary search for a bad commit

git bisect bad

Mark current commit as bad

git bisect good <commit>

Mark a known-good commit

git bisect reset

End bisect session

git reflog

Show history of HEAD movements (recovery tool)

git reflog expire --expire=now --all

Expire all reflog entries

git gc --prune=now

Clean up and optimize repository

git submodule add <url>

Add a submodule

git submodule update --init --recursive

Initialize all submodules

git archive --format=zip HEAD > out.zip

Export 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

*.log

Ignore all .log files

node_modules/

Ignore node_modules directory

!important.log

Un-ignore a specific file (exception)

/dist

Ignore 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

Nicht das Richtige dabei?

Wir bauen kostenlose Tools nach Community-Feedback. Schlagen Sie heute noch ein Tool vor!

Git Cheat Sheet — Free Online Tool | FreeTool24