Git-Merkzettel
Kurzreferenz für gängige Git-Befehle
Einrichtung & Konfiguration
| Befehl | Beschreibung |
|---|---|
| git init | Initialize a new Git repository |
| git config --global user.name "Name" | Set global username |
| git config --global user.email "email" | Set global email |
| git config --list | List all Git configuration |
| git clone <url> | Clone a repository from URL |
Verzweigungen
| Befehl | Beschreibung |
|---|---|
| git branch | List local branches |
| git branch <name> | Create a new branch |
| git checkout <branch> | Switch to a branch |
| git checkout -b <name> | Create and switch to a new branch |
| git merge <branch> | Merge a branch into current |
| git branch -d <name> | Delete a branch |
Commits
| Befehl | Beschreibung |
|---|---|
| git add <file> | Stage a file for commit |
| git add . | Stage all changes |
| git commit -m "msg" | Commit staged changes with message |
| git commit -am "msg" | Add and commit all tracked changes |
| git commit --amend | Amend the last commit |
Remote
| Befehl | Beschreibung |
|---|---|
| git remote -v | List remote repositories |
| git remote add <name> <url> | Add a remote repository |
| git push <remote> <branch> | Push to a remote branch |
| git push -u <remote> <branch> | Push and set upstream |
| git pull | Pull changes from remote |
| git fetch | Fetch changes without merging |
Diff & Vergleich
| Befehl | Beschreibung |
|---|---|
| git diff | Show unstaged changes |
| git diff --staged | Show staged changes |
| git diff <branch>..<branch> | Diff between two branches |
Log & Verlauf
| Befehl | Beschreibung |
|---|---|
| git log | View commit history |
| git log --oneline | View compact commit history |
| git log --graph | View commit history as graph |
Zurücksetzen & Rückgängig
| Befehl | Beschreibung |
|---|---|
| git reset <file> | Unstage a file |
| git reset --soft HEAD~1 | Undo last commit, keep changes staged |
| git reset --hard HEAD~1 | Undo last commit, discard changes |
| git revert <commit> | Revert a commit by creating a new one |
Stash
| Befehl | Beschreibung |
|---|---|
| git stash | Stash working directory changes |
| git stash pop | Apply and remove latest stash |
| git stash list | List all stashes |
| git stash drop | Discard the latest stash |
Verwendung
Durchsuchen Sie gängige Git-Befehle, sortiert nach Kategorie. Verwenden Sie den Suchfilter, um bestimmte Befehle schnell zu finden. Jeder Befehl zeigt seine Syntax und eine kurze Beschreibung.