⚡ Dev Cheat Sheet

Git • Docker • Docker Compose • Useful Commands

🔌 Git

Init a repo

git init

Create a new local repository

Clone a repo

git clone https://github.com/user/repo.git

Download a remote repository

Check status

git status

Show changed/staged files

Stage files

git add .

Stage all changes for commit

Commit

git commit -m "feat: add login"

Save staged changes with a message

Push

git push origin main

Upload commits to remote

Pull

git pull origin main

Fetch + merge remote changes

Create branch

git checkout -b feature/login

Create and switch to new branch

Switch branch

git checkout main

Switch to an existing branch

Merge branch

git merge feature/login

Merge a branch into current one

View log

git log --oneline --graph

Show compact commit history

Stash changes

git stash

Temporarily save uncommitted work

Apply stash

git stash pop

Restore last stashed changes

Undo last commit (keep files)

git reset --soft HEAD~1

Undo commit but keep changes staged

Discard file changes

git checkout -- file.txt

Restore file to last commit state

Delete branch

git branch -d feature/login

Remove a local branch

Show remotes

git remote -v

List remote URLs

Diff changes

git diff

Show unstaged file differences

🐳 Docker

Build image

docker build -t myapp:latest .

Build image from Dockerfile in current dir

Run container

docker run -d -p 8080:80 --name web myapp

Run detached, map port 8080 to 80

List running containers

docker ps

Show active containers

List all containers

docker ps -a

Include stopped containers

Stop container

docker stop web

Gracefully stop a running container

Remove container

docker rm web

Delete a stopped container

List images

docker images

Show all local images

Remove image

docker rmi myapp:latest

Delete a local image

View logs

docker logs -f web

Follow container logs in real-time

Exec into container

docker exec -it web /bin/sh

Open shell inside running container

Pull image

docker pull nginx:alpine

Download image from Docker Hub

Inspect container

docker inspect web

Show detailed container info (IP, mounts…)

Prune unused data

docker system prune -a

Remove all unused images, containers, networks

Copy file to container

docker cp file.txt web:/app/

Copy local file into container

List volumes

docker volume ls

Show all Docker volumes

List networks

docker network ls

Show all Docker networks

📦 Docker Compose

Start services

docker compose up -d

Start all services in background

Stop services

docker compose down

Stop and remove containers + networks

Stop + remove volumes

docker compose down -v

Also remove named volumes

Rebuild and start

docker compose up -d --build

Force rebuild images before starting

View logs

docker compose logs -f api

Follow logs for a specific service

List services

docker compose ps

Show running compose services

Exec into service

docker compose exec api sh

Open shell in a running service

Restart a service

docker compose restart api

Restart one specific service

Scale service

docker compose up -d --scale api=3

Run 3 instances of the api service

Pull latest images

docker compose pull

Download latest images for all services

🛠 Useful Commands

Find files by name

find . -name "*.log"

Search for files matching a pattern

Search text in files

grep -r "TODO" ./src

Recursively search for text in folder

Disk usage

du -sh *

Show size of each item in current dir

Free disk space

df -h

Show available disk space

Watch file changes

watch -n 2 ls -la

Re-run command every 2 seconds

Check port in use

lsof -i :3000

Show which process uses port 3000

Kill process on port

kill -9 $(lsof -t -i :3000)

Force kill process using port 3000

Tar compress

tar -czf archive.tar.gz ./folder

Compress folder to .tar.gz

Tar extract

tar -xzf archive.tar.gz

Extract .tar.gz archive

SSH into server

ssh user@192.168.1.10

Connect to remote server via SSH

SCP file to server

scp file.txt user@server:/path/

Copy file to remote server

Curl GET request

curl -s https://api.example.com/data | jq

Fetch URL and pretty-print JSON

Curl POST request

curl -X POST -H "Content-Type: application/json" -d '{"key":"val"}' https://api.example.com

Send JSON POST request

Make file executable

chmod +x script.sh

Add execute permission to file

Show environment variable

echo $PATH

Print the value of a variable

Count lines in file

wc -l file.txt

Count number of lines

Tail log file

tail -f /var/log/app.log

Follow new lines in a log file

Process list

ps aux | grep node

Find running processes by name