Skip to content

Instantly share code, notes, and snippets.

@ignatiusreza
Last active February 28, 2023 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ignatiusreza/0fa82a586c2f96abb565ee0053e3986b to your computer and use it in GitHub Desktop.
Save ignatiusreza/0fa82a586c2f96abb565ee0053e3986b to your computer and use it in GitHub Desktop.
custom git alias and script
Various custom bash & git "function"
#!/bin/bash
docker ps -a -q -f status=exited | xargs -r docker rm -v 2> /dev/null
docker images -f "dangling=true" -q | xargs -r docker rmi 2> /dev/null
docker volume ls -qf dangling=true | xargs -r docker volume rm 2> /dev/null
docker secret ls -q | xargs -r docker secret rm 2> /dev/null
#!/bin/bash
docker ps -a -q | xargs -r docker rm -v 2> /dev/null
docker images -q | xargs -r docker rmi 2> /dev/null
docker volume ls -q | xargs -r docker volume rm 2> /dev/null
docker secret ls -q | xargs -r docker secret rm 2> /dev/null
docker system prune --force --volumes
git log --all -M -C --name-only --format='format:' "$@" \
| sort \
| grep -v '^$' \
| uniq -c \
| sort -n \
| awk 'BEGIN {print "count\tfile"} {print $1 "\t" $2}'
#!/bin/bash
if [[ $(git ls-remote origin develop | wc -l) == 1 ]]; then
echo "develop"
else
git main-branch
fi
#!/bin/bash
# Yo Dawg, I heard you like git
git "$@"
#!/bin/bash
# cleanup local git branches: remove merged branches and branches with missing remotes
set -e
git fetch -p
default=$(git default-branch)
main=$(git main-branch)
if branches=$(git branch --merged | grep -v '*' | grep -v $default | grep -v $main | grep -v "features/"); then
echo $branches | xargs git branch -d
else
echo Merged branches not found
fi
if branches=$(git branch -vv | grep -v '^*' | awk '/: gone]/{print $1}' | grep .); then
echo $branches | xargs git branch -D
else
echo No branches with missing remotes
fi
#!/bin/bash
if [[ $(git ls-remote origin main | wc -l) == 1 ]]; then
echo "main"
else
echo "master"
fi
#!/bin/bash
# pull latest remote and prune both remote and local branches
set -e
git refresh
git remote prune origin
git localprune
#!/bin/bash
# pull latest remote either from upsteam or origin
# update origin if upstream is found
set -e
default=$(git default-branch)
git checkout $default
if [[ git ls-remote --quiet --exit-code upstream 2> /dev/null ]] then
git fetch upstream $default
git merge upstream/$default
git push origin $default
else
git pull
fi
#!/bin/bash
# pull latest version of certain branch from remote, discarding local changes and resolving conflict
set -e
default=$(git default-branch)
main=$(git main-branch)
if branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null); then
if [[ "$branch" == "HEAD" ]]; then
echo In a detached head && exit 1
elif [[ "$branch" == "$default" ]]; then
echo In $default branch && exit 1
elif [[ "$branch" == "$main" ]]; then
echo In $main branch && exit 1
else
git checkout $default
git pull
git branch -D $branch
git checkout $branch
git status
fi
else
echo Unable to get current branch && exit 1
fi
#!/bin/bash
find -name 'node_modules' -exec rm -rf {} +
#!/bin/bash
set -e
skadoosh-node-modules
yarn
yarn check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment