Git Tricks

Cleanup Unrefs

#!/bin/bash
set -xeuo pipefail
git reflog expire --all --expire=now
git gc --prune=now --aggressive

Cleanup Workflow Runs

#!/bin/bash
set -xeuo pipefail
PATH_NAME="repos/$1/actions/runs"
gh api "$PATH_NAME" --paginate --jq ".workflow_runs[] | .id" |
  xargs -P 10 -I % gh api --silent -X DELETE "$PATH_NAME/%"

Fast Commit

#!/bin/bash
set -xeuo pipefail
NOW="$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
git add --all
git commit --all --message "Regular update: $NOW"
git push --set-upstream origin HEAD

Mirror + Bundle

#!/bin/bash
set -xeuo pipefail
SOURCE="$1"
BUNDLED="$(realpath "$2")"
MIRRORED="$(mktemp -d)"
git clone --mirror "$SOURCE" "$MIRRORED"
git -C "$MIRRORED" bundle create "$BUNDLED" --all
rm -rf "$MIRRORED"