DangKit
All Cheatsheets

Git Cheat Sheet

# Git Cheat Sheet ## Setup ``` git config --global user.name "Name" git config --global user.email "[email protected]" ``` ## Creating ``` git init # New repo git clone <url> # Clone repo git clone --depth 1 <url> # Shallow clone ``` ## Staging ``` git add <file> # Stage file git add . # Stage all git add -p # Interactive git reset HEAD <file> # Unstage ``` ## Committing ``` git commit -m "message" # Commit git commit --amend # Fix last commit git commit --no-verify # Skip hooks ``` ## Branching ``` git branch # List branches git branch <name> # Create branch git checkout <branch> # Switch git checkout -b <branch> # Create + switch git branch -d <branch> # Delete ``` ## Remote ``` git remote add origin <url> git push -u origin main git push --force # Careful! git pull --rebase # Pull + rebase ``` ## History ``` git log --oneline -20 git log --graph --all git diff # Unstaged changes git diff --staged # Staged changes git blame <file> ``` ## Undo ``` git restore <file> # Discard changes git restore --staged <file> # Unstage git revert <commit> # New undo commit git reset --soft HEAD~1 # Undo commit, keep changes git reset --hard HEAD~1 # Undo commit, discard changes ``` ## Stash ``` git stash # Stash changes git stash pop # Apply stash git stash list # List stashes ```
DangKit โ€” 139+ Free Online Tools: PDF, Dev, Design, Finance & More