Skip to content

Instantly share code, notes, and snippets.

@Tlaloc-Es
Last active March 29, 2023 09:44
Show Gist options
  • Save Tlaloc-Es/4b623ac1b59823994b193423f1492edd to your computer and use it in GitHub Desktop.
Save Tlaloc-Es/4b623ac1b59823994b193423f1492edd to your computer and use it in GitHub Desktop.
Utils bash scripts as python developer

GIT

Change branch witouth commit

git stash save -u "message"
git stash list
git checkout other-branch

to unstash

git apply stash@{6} or git stash pop

Reset branch with origin

git fetch origin
git reset --hard origin/master

Git log with tree

git log --graph --pretty='\''%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'\'' --all

Delete branch merged in master

git fetch
git branch --merged master | grep -v "^\* master" | xargs -n 1 -r git branch -d

Delete branches taht no longer exist on the remote

git fetch
git branch -vv | grep ': gone]' | grep -v '\*' | awk '{ print $1; }' | xargs -r git branch -d

Bash

Filter

Grep over log

find . --maxdepth 2 -iname log.log -type f -exec grep -m 1 "Trace" {} +

Filter lines with content

cat file | grep word

Skip lines with content

cat file | grep -v word

Delete all pycache

find . | grep -E "(/__pycache__$|\.pyc$|\.pyo$)" | xargs rm -rf

Compress

Compress tar.gz

tar -cvzf code.tar.gz code/*
tar -cvzf code.tar.gz code/. # Hidden files

Uncompress tar.gz

tar -xf cide.tar.gz

Docker

  • Stop the container(s) using the following command: docker-compose down
  • Delete all containers using the following command: docker rm -f $(docker ps -a -q)
  • Delete all volumes using the following command: docker volume rm $(docker volume ls -q)
  • Restart the containers using the following command: docker-compose up -d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment