Published on
Updated on 

Developer Cheat Sheet

Authors
This post will be a living document and updated as I find more commands 

git

Delete all local git branches that don't have a remote, except master, stable, and main

git branch --merged master --no-color | grep -v "master\|stable\|main" | xargs git branch -d

Merge down git fork or template into your branch

If you're not merging in often, this will get messy depending on the velocity of changes for the git fork or template

git remote add <template/fork> <URL of the template/fork repo>
git fetch --all
git merge <template/fork>/<branch to merge> --allow-unrelated-histories

git remote add <template/fork> <URL of the template repo> adds an additional remote repository to your local repository. Name the git remote whatever you like (I use template or fork). Append the template or fork URL (ending in .git)

git fetch --all pulls down the latest changes to the remote

git merge <templatefork>/[=<branch to merge> --allow-unrelated-histories merges in the template or fork code. For templates you'll need the --allow-unrelated-histories flag as you won't have the commit history of the template.

Good luck dealing with merge conflicts if you're not doing this often.

Difference between a git fork and a git template

A git fork will keep all commit history when you create it. A git template will be created with the current state as the initial commit.

linux

Find and kill a process running on a specific port

sudo kill -9 `sudo lsof -t -i:<port>`

lsof list of files (also used to list related processes)

-t show only process IDs

-i show only internet connection related process

:<port> show only processes on this port number (e.g. 3000)

kill command to kill the process

-9 forcefully

sudo execute command with admin privileges

Set an environment variable

VARIABLE_NAME=<value>

next.js

Bootstrap app with TailwindCSS

npx create-next-app -e with-tailwindcss

docker

Format docker ps output

docker ps --format "{{.<field-1>}}: {{.<field-2>}}: {{.<field-n>}}"

Enter started container through app CLI

docker exec -it <containerName> <app>

app can be anything installed on the box (e.g. bash, mongo)

delete all docker images which are not in use

docker rmi -f $(docker images -aq)

force stop and delete all docker containers

docker rm -f $(docker ps -a -q)

delete all docker volumes which are not in use

docker volume rm $(docker volume ls -q)

delete all docker resources which are not in use - including volumes

docker system prune -a --volumes
Use the social icons in the footer if there's a command you believe should be added to the list!