Common commands and what they do
Git
Add latest changes to current git commit or change commit message | git commit --amend |
Same as above except don't edit git message | git commit --amend --no-edit |
Saves local changes | git stash |
Saves the stash with a message for easier retrieval | git stash save "message" |
List all changes that have been added to git stash | git stash list |
Delete latest git stash | git stash drop |
Clean everything in git stash | git stash clear |
Undo commit but keep all changes in staging | git reset --soft HEAD~1 |
Discard all local changes to all files permanently | git reset --hard |
Unstage everything - retain changes | git reset |
Undos changes on the file | git checkout "filename" |
Reverts changes in that commit | git revert "id" |
Display git branch | tigg --all |
Reset to master | git reset --hard origin/master |
Can find accidently deleted commits | git reflog |
Check what has changed since the last commit (if not git added) | git diff myfile.txt |
Check what has changed since the last commit (if git added) | git diff --cached myfile.txt |
Delete all local branches except for “main” | git branch | grep -v "main" | xargs git branch -D |
gcm;gfa;ggpull;gco -;grbm | Rebase branch onto main |
gsta;gcm;gfa;ggpull;gco -;grbm;gstp | Stash local changes, rebase branch onto main then pop changes |
Terminal
Saves the current working directory in memory | pushd "path name" |
Returns to the path at the top of the directory stack. | popd "path name" |
List process and filter by the word "node" | ps auxww | grep node |
Check port in use | sudo lsof -i tcp:"port number" |
Clear line | ctrl c |
Move cursor to start of line | ctrl a |
Move cursor to end of line | ctrl e |
Cut all | ctrl u |
Cut word | ctrl w |
Paste word | ctrl y |
Next word | option f |
Previous word | option b |
Find things | find path -name filename.txt |
Execute command on found files (the brackets represent the file found) | find path -name filename.txt -exec command {} \; |
List all commands you're authorised to run | sudo -l |
Check your local IP address if using a wireless connection | ipconfig getifaddr en1 |
Check your local IP address if connected via ethernet | ipconfig getifaddr en0 |
List open files | lsof -nP +c 15 | grep LISTEN |
Run yarn interactively | yarn upgrade-interactive |
Run yarn interactively (include major updates) | yarn upgrade-interactive --latest |
Run as user | sudo -u user command e.g. sudo -u user1 vim |
Count number of files | ls | wc -l |
iTerm
Form vertical pane | cmd-d |
Form horizontal pane | cmd-shift-d |
Toggle between maximising current pane or restoring hidden panes | cmd-shift-enter |
Docker
Removes all dangling images (not associated with a container) | docker image prune |
Removes any stopped containers and all unused images (not just dangling images) | docker image prune -a |
Cleans up any resources (images, containers, volumes, and networks) that are dangling (not associated with a container) | docker system prune -f |
View all docker containers in existence | docker container ls |
View all images in existence | docker image ls |
View all running containers | docker ps |
Rebuid container | docker-compose build container name |
Connect into container | docker exec -it "container-id" /bin/bash |
Postgres
Connect to Postgres | psql postgres://$db_username;$db_password@$db_address/$db_name |
Display all tables | \dt |
Display table | \d "tablename"; |
Quit | \q |
Delete table | DROP table "tablename"; |
export PATH=/usr/local/opt/node@16/bin:$PATH
export PATH=/usr/local/opt/node@16/bin:$PATH
export PATH=/usr/local/opt/node@16/bin:$PATH
export PATH=/usr/local/opt/node@16/bin:$PATH
export PATH=/usr/local/opt/node@16/bin:$PATH
export PATH=/usr/local/opt/node@16/bin:$PATH
export PATH=/usr/local/opt/node@16/bin:$PATH