Recipes
Setup Useful Git Aliases
Recommended aliases from git documentation.
# Shortening Aliasesgit config --global alias.co checkoutgit config --global alias.br branchgit config --global alias.cm commitgit config --global alias.st status# Simplify Common Actionsgit config --global alias.unstage 'reset HEAD --'git config --global alias.last 'log -1 HEAD'
Git Feature Branch Workflow
Create a feature branch, make changes, and merge back to main.
# Create and switch to feature branchgit checkout -b feature/my-feature# Make your changes, then stage and commitgit add .git commit -m "Add new feature"# Push feature branch to remotegit push -u origin feature/my-feature# After PR is merged, cleanupgit checkout maingit pullgit branch -d feature/my-feature
Undo Last Git Commit
Undo the last commit while keeping changes staged.
# Undo last commit, keep changes stagedgit reset --soft HEAD~1# Or undo and unstage changesgit reset HEAD~1# Or completely discard changes (DESTRUCTIVE)git reset --hard HEAD~1
Git Stash Workflow
Save work in progress, switch branches, and restore.
# Save current changes to stashgit stash push -m "WIP: work in progress"# List all stashesgit stash list# Apply most recent stash (keeps stash)git stash apply# Apply and remove most recent stashgit stash pop# Apply a specific stashgit stash apply stash@{0}
Interactive Git Rebase
Squash, reorder, or edit recent commits.
# Rebase last N commits interactivelygit rebase -i HEAD~3# In the editor, change 'pick' to:# - 'squash' or 's' to combine with previous# - 'reword' or 'r' to edit message# - 'drop' or 'd' to remove commit# - 'edit' or 'e' to stop and amend# If you mess up, abort:git rebase --abort
Docker Compose Dev Environment
Start, stop, and manage a Docker Compose environment.
# Start all services in backgrounddocker compose up -d# View logs (follow mode)docker compose logs -f app# Rebuild and restart a specific servicedocker compose up -d --build app# Stop all servicesdocker compose down# Stop and remove volumes (DESTRUCTIVE)docker compose down -v
Docker Cleanup
Remove unused Docker resources to free disk space.
# Remove stopped containersdocker container prune -f# Remove unused imagesdocker image prune -f# Remove unused volumes (CAREFUL - data loss)docker volume prune -f# Nuclear option: remove everything unuseddocker system prune -a -f --volumes# Check disk usagedocker system df
Docker Build and Push
Build a Docker image and push to a registry.
# Build with tagdocker build -t myapp:latest .# Tag for registrydocker tag myapp:latest ghcr.io/username/myapp:latest# Push to registrydocker push ghcr.io/username/myapp:latest
SSH Key Setup
Generate SSH key and add to ssh-agent.
# Generate new SSH keyssh-keygen -t ed25519 -C "[email protected]"# Start ssh-agenteval "$(ssh-agent -s)"# Add key to agentssh-add ~/.ssh/id_ed25519# Copy public key to clipboard (macOS)cat ~/.ssh/id_ed25519.pub | pbcopy# Test connection (for GitHub)ssh -T [email protected]
Find and Kill Process by Port
Find which process is using a port and kill it.
# Find process using port (macOS/Linux)lsof -i :3000# Kill process by PIDkill -9 12345# One-liner to kill process on port (macOS)lsof -ti :3000 | xargs kill -9# Alternative using fuser (Linux)fuser -k 3000/tcp
Disk Space Analysis
Find what's using disk space.
# Show disk usage summarydf -h# Find largest directories in current folderdu -sh * | sort -hr | head -20# Find largest files (over 100MB)find . -type f -size +100M -exec ls -lh {} \;# Interactive disk usage (if ncdu installed)ncdu .
Create Node.js Project
Initialize a new Node.js project with TypeScript.
# Create directory and initmkdir my-project && cd my-projectnpm init -y# Install TypeScript and typesnpm install -D typescript @types/node ts-node# Create tsconfignpx tsc --init# Create source directorymkdir src && touch src/index.ts# Add scripts to package.jsonnpm pkg set scripts.build="tsc"npm pkg set scripts.dev="ts-node src/index.ts"
Quick HTTP Server
Serve current directory over HTTP for testing.
# Python 3python3 -m http.server 8000# Node.js (npx)npx serve -p 8000# PHPphp -S localhost:8000
Generate Random Password
Generate a secure random password.
# Using opensslopenssl rand -base64 32# Using /dev/urandom (alphanumeric)cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1# Using Pythonpython3 -c "import secrets; print(secrets.token_urlsafe(32))"
Tail Logs with Highlight
Monitor log files with pattern highlighting.
# Tail with grep highlighttail -f /var/log/app.log | grep --color=always -E 'ERROR|$'# Multiple patternstail -f /var/log/app.log | grep --color=always -E 'ERROR|WARN|$'# Using less for scrollbackless +F /var/log/app.log
Sync Files with Rsync
Efficiently sync files between locations.
# Sync local to remotersync -avz --progress ./src/ [email protected]:/backup/src/# Sync with delete (mirror exactly)rsync -avz --delete ./src/ /backup/src/# Dry run (see what would happen)rsync -avzn ./src/ /backup/src/# Exclude patternsrsync -avz --exclude='node_modules' --exclude='.git' ./src/ /backup/src/
made by @shridhargupta | data from tldr-pages