Bash public

Git Worktree Status

Share this script safely, inspect its metadata, and copy the exact command you need.

Dashboard

Ready to run

One-liner

Copy the command, then review before execution.
curl -fsSL https://runny.sh/r/CKAHDY58FGWR | bash

Current version: 1.1 · Updated by Godmode · 2026-09-07 02:38:59.209

At a glance

Script metadata

Slug
CKAHDY58FGWR
Fetches
0
Size
1844 B · 66 lines
Expires
never
Last fetch
Created
2026-09-07 00:35:59.317
Description
Dirty files, branch, and unpushed commits

Readable before runnable

Preview

#!/usr/bin/env bash
# Git worktree status
# Read-only: current branch, dirty files, and unpushed commits for the cwd.
# Exit 0 if clean and in sync, 1 if dirty/unpushed/no upstream, 2 if not a git repo.
# Hosted on Runny.sh. Review the script page before you run it.

set -u

status=0
note() { printf '%s\n' "$*"; }
bump() {
  case $1 in
    crit) status=2 ;;
    warn) [ "$status" -lt 1 ] && status=1 ;;
  esac
}

note "=== Git worktree status ==="
note "Cwd:      $(pwd)"
if ! command -v git >/dev/null 2>&1; then
  note "git:      not found in PATH"
  note "Result: CRITICAL"
  exit 2
fi
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
  note "Repo:     cwd is not a git work tree"
  note "Result: CRITICAL"
  exit 2
fi

branch=$(git branch --show-current 2>/dev/null || git rev-parse --abbrev-ref HEAD 2>/dev/null || printf unknown)
head=$(git rev-parse --short HEAD 2>/dev/null || printf unknown)
note "Branch:   ${branch}"
note "HEAD:     ${head}"

dirty=$(git status --porcelain 2>/dev/null || true)
dirty_n=$(printf '%s\n' "$dirty" | awk 'NF {n++} END {print n+0}')
note "Dirty:    ${dirty_n} path(s)"
if [ "$dirty_n" -gt 0 ]; then
  printf '%s\n' "$dirty" | awk 'NR <= 12 {print "  " $0}'
  if [ "$dirty_n" -gt 12 ]; then
    note "  ... $((dirty_n - 12)) more"
  fi
  bump warn
fi

if git rev-parse --abbrev-ref '@{upstream}' >/dev/null 2>&1; then
  ahead=$(git rev-list --count '@{upstream}..HEAD' 2>/dev/null || printf 0)
  behind=$(git rev-list --count 'HEAD..@{upstream}' 2>/dev/null || printf 0)
  note "Upstream: ahead ${ahead}, behind ${behind}"
  if [ "$ahead" -gt 0 ] || [ "$behind" -gt 0 ]; then
    bump warn
  fi
else
  note "Upstream: none configured"
  bump warn
fi
note ""

case $status in
  0) note "Result: HEALTHY" ;;
  1) note "Result: WARNING" ;;
  *) note "Result: CRITICAL" ;;
esac
exit "$status"

Raw endpointhttps://runny.sh/r/CKAHDY58FGWR

See something unsafe?

Report this script

Tell us why it should come down. Anyone can also report a URL at /abuse.

Restore revision