{"id":4551,"date":"2025-11-12T12:20:38","date_gmt":"2025-11-12T11:20:38","guid":{"rendered":"https:\/\/vielhuber.de\/?p=4551"},"modified":"2025-11-12T12:41:09","modified_gmt":"2025-11-12T11:41:09","slug":"git-status-2-0","status":"publish","type":"post","link":"https:\/\/vielhuber.de\/blog\/git-status-2-0\/","title":{"rendered":"git status 2.0"},"content":{"rendered":"\n<p>Wer morgens zuerst <code>git status<\/code> tippt und danach Kaffee trinkt, wird dieses kleine Helferlein lieben. Gerade wenn viele Webprojekte parallel entwickelt werden, lohnt sich eine kompakte \u00dcbersicht: Wo ist der Arbeitsbaum sauber, wo h\u00e4ngen ungemergte \u00c4nderungen, und wo wartet ein Pull\/Push? Ein kleines Shell-Werkzeug reicht aus \u2013 solange es robust mit Leerzeichen\/Unicode in Pfaden umgeht und sich nicht an h\u00e4ngenden Remotes verschluckt.<\/p>\n\n\n\n<!--more-->\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/usr\/bin\/env bash\n\nset -Eeuo pipefail\nexport LC_ALL=C\n\n# Check if a command exists (no output).\nhave() { command -v \"$1\" >\/dev\/null 2>&amp;1; }\n\n# Ensure we have a `sort` that supports -z (NUL-delimited) input.\nSORT_BIN=\"sort\"\nif ! \"$SORT_BIN\" -z &lt;\/dev\/null 2>\/dev\/null; then\n&nbsp;&nbsp;if have gsort &amp;&amp; gsort -z &lt;\/dev\/null 2>\/dev\/null; then\n&nbsp;&nbsp;&nbsp;&nbsp;SORT_BIN=\"gsort\"\n&nbsp;&nbsp;else\n&nbsp;&nbsp;&nbsp;&nbsp;printf 'Error: This script requires \"sort -z\" (GNU coreutils). Install coreutils (gsort).\\n' >&amp;2\n&nbsp;&nbsp;&nbsp;&nbsp;exit 1\n&nbsp;&nbsp;fi\nfi\n\n# Use GNU `timeout` if available; otherwise try `gtimeout` (macOS); otherwise no timeout.\nTIMEOUT_BIN=\"timeout\"\nif ! have \"$TIMEOUT_BIN\"; then\n&nbsp;&nbsp;if have gtimeout; then\n&nbsp;&nbsp;&nbsp;&nbsp;TIMEOUT_BIN=\"gtimeout\"\n&nbsp;&nbsp;else\n&nbsp;&nbsp;&nbsp;&nbsp;TIMEOUT_BIN=\"\"\n&nbsp;&nbsp;fi\nfi\n\n# Require git.\nif ! have git; then\n&nbsp;&nbsp;printf 'Error: \"git\" not found.\\n' >&amp;2\n&nbsp;&nbsp;exit 1\nfi\n\n# Remove a leading \".\/\" from a path for cleaner output.\ntrim_dot_slash() {\n&nbsp;&nbsp;case \"$1\" in\n&nbsp;&nbsp;&nbsp;&nbsp;.\/*) printf '%s\\n' \"${1#.\/}\" ;;\n&nbsp;&nbsp;&nbsp;&nbsp;*)   printf '%s\\n' \"$1\" ;;\n&nbsp;&nbsp;esac\n}\n\n# Legend + divider (as requested)\nprintf '\\n\ud83d\udfe2: clean\\n\ud83d\udfe1: behind\/ahead\\n\ud83d\udd34: modified\\n\\n----------------------------------\\n\\n'\n\n# Find all .git directories, NUL-delimited; sort NUL-delimited; iterate safely.\nfind . -type d -name .git -print0 \\\n| \"$SORT_BIN\" -z \\\n| while IFS= read -r -d '' gitdir; do\n&nbsp;&nbsp;&nbsp;&nbsp;repo=\"${gitdir%\/.git}\"\n&nbsp;&nbsp;&nbsp;&nbsp;display_path=\"$(trim_dot_slash \"$repo\")\"\n\n&nbsp;&nbsp;&nbsp;&nbsp;# Skip anything that isn't a proper work tree (safety check).\n&nbsp;&nbsp;&nbsp;&nbsp;if ! git -C \"$repo\" rev-parse --is-inside-work-tree >\/dev\/null 2>&amp;1; then\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;continue\n&nbsp;&nbsp;&nbsp;&nbsp;fi\n\n&nbsp;&nbsp;&nbsp;&nbsp;# Working tree status; include untracked files for a strict \"red\" signal.\n&nbsp;&nbsp;&nbsp;&nbsp;status_out=\"$(git -C \"$repo\" status --porcelain=v1 || true)\"\n\n&nbsp;&nbsp;&nbsp;&nbsp;# Upstream divergence check (only if an upstream is configured).\n&nbsp;&nbsp;&nbsp;&nbsp;ahead=0\n&nbsp;&nbsp;&nbsp;&nbsp;behind=0\n&nbsp;&nbsp;&nbsp;&nbsp;if git -C \"$repo\" rev-parse --abbrev-ref --symbolic-full-name '@{u}' >\/dev\/null 2>&amp;1; then\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# Refresh refs; protect with timeout so a hanging remote doesn't stall the loop.\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if &#91; -n \"$TIMEOUT_BIN\" ]; then\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"$TIMEOUT_BIN\" 10s git -C \"$repo\" fetch --all --prune >\/dev\/null 2>&amp;1 || true\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;git -C \"$repo\" fetch --all --prune >\/dev\/null 2>&amp;1 || true\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fi\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# Count commits only on our side (ahead) and only on upstream's side (behind).\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ahead=\"$(git  -C \"$repo\" rev-list --count --left-only  HEAD...@{u} 2>\/dev\/null || echo 0)\"\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;behind=\"$(git -C \"$repo\" rev-list --count --right-only HEAD...@{u} 2>\/dev\/null || echo 0)\"\n&nbsp;&nbsp;&nbsp;&nbsp;fi\n\n&nbsp;&nbsp;&nbsp;&nbsp;# Decide the signal:\n&nbsp;&nbsp;&nbsp;&nbsp;# - RED if the working tree isn't clean\n&nbsp;&nbsp;&nbsp;&nbsp;# - YELLOW if clean but ahead\/behind of upstream\n&nbsp;&nbsp;&nbsp;&nbsp;# - GREEN otherwise\n&nbsp;&nbsp;&nbsp;&nbsp;if &#91; -n \"$status_out\" ]; then\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf '\ud83d\udd34 %s\\n' \"$display_path\"\n&nbsp;&nbsp;&nbsp;&nbsp;else\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if &#91; \"${ahead:-0}\" -gt 0 ] || &#91; \"${behind:-0}\" -gt 0 ]; then\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf '\ud83d\udfe1 %s\\n' \"$display_path\"\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf '\ud83d\udfe2 %s\\n' \"$display_path\"\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fi\n&nbsp;&nbsp;&nbsp;&nbsp;fi\n&nbsp;&nbsp;done<\/code><\/pre>\n\n\n\n<p>Man muss das Script noch mit <code>chmod +x ~\/path\/to\/script.sh<\/code> ausf\u00fchrbar machen und kann einen Alias einrichten, um wertvolle Tipparbeit zu sparen: Hier f\u00fcgt man in seine <code>~\/.bashrc<\/code> \/ <code>~\/.zshrc<\/code> \/ <code>~\/.bash_profile<\/code> den Eintrag <code>alias gscan='bash \/path\/to\/script.sh'<\/code> hinzu. Ab dann gen\u00fcgt ein schlichtes <code>gscan<\/code> im gew\u00fcnschten Wurzelverzeichnis.<\/p>\n\n\n\n<p>Ein Wort, warum der zweite Durchlauf sp\u00fcrbar flotter ist: Beim ersten Lauf muss das Dateisystem noch alles abgrasen; danach sind Metadaten und viele <code>.git<\/code>-Strukturen im Page-Cache der OS-Kernel gelandet sowie Referenzen und Commit-Graphen bereits aufgew\u00e4rmt sind. Das n\u00e4chste <code>fetch<\/code> \u00fcbertr\u00e4gt meist nur noch kleine Deltas. Kein Dashboard, kein Overhead \u2013 ein schneller Status-Snapshot direkt im Terminal.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Wer morgens zuerst git status tippt und danach Kaffee trinkt, wird dieses kleine Helferlein lieben. Gerade wenn viele Webprojekte parallel entwickelt werden, lohnt sich eine kompakte \u00dcbersicht: Wo ist der Arbeitsbaum sauber, wo h\u00e4ngen ungemergte \u00c4nderungen, und wo wartet ein Pull\/Push? Ein kleines Shell-Werkzeug reicht aus \u2013 solange es robust mit Leerzeichen\/Unicode in Pfaden umgeht [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"gtbabel_prevent_lngs":"","gtbabel_alt_lng":"","footnotes":""},"categories":[1],"tags":[],"class_list":{"0":"post-4551","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-blog"},"acf":[],"yoast_head":"<title>git status 2.0 &#060; Vielhuber David<\/title>\n<meta name=\"description\" content=\"Wer morgens zuerst git status tippt und danach Kaffee trinkt, wird dieses kleine Helferlein lieben. Gerade wenn viele Webprojekte parallel entwickelt\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/vielhuber.de\/blog\/git-status-2-0\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"git status 2.0 &#060; Vielhuber David\" \/>\n<meta property=\"og:description\" content=\"Wer morgens zuerst git status tippt und danach Kaffee trinkt, wird dieses kleine Helferlein lieben. Gerade wenn viele Webprojekte parallel entwickelt\" \/>\n<meta property=\"og:url\" content=\"https:\/\/vielhuber.de\/blog\/git-status-2-0\/\" \/>\n<meta property=\"og:site_name\" content=\"Vielhuber David\" \/>\n<meta property=\"article:published_time\" content=\"2025-11-12T11:20:38+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-11-12T11:41:09+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/vielhuber.de\/wp-content\/uploads\/about.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"700\" \/>\n\t<meta property=\"og:image:height\" content=\"552\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"David\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vielhuber\" \/>\n<meta name=\"twitter:site\" content=\"@vielhuber\" \/>\n<meta name=\"twitter:label1\" content=\"Verfasst von\" \/>\n\t<meta name=\"twitter:data1\" content=\"David\" \/>\n\t<meta name=\"twitter:label2\" content=\"Gesch\u00e4tzte Lesezeit\" \/>\n\t<meta name=\"twitter:data2\" content=\"1\u00a0Minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/vielhuber.de\\\/blog\\\/git-status-2-0\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/vielhuber.de\\\/blog\\\/git-status-2-0\\\/\"},\"author\":{\"name\":\"David\",\"@id\":\"https:\\\/\\\/vielhuber.de\\\/#\\\/schema\\\/person\\\/64d4ff14713d413ea4d9b210d0c2c6ef\"},\"headline\":\"git status 2.0\",\"datePublished\":\"2025-11-12T11:20:38+00:00\",\"dateModified\":\"2025-11-12T11:41:09+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/vielhuber.de\\\/blog\\\/git-status-2-0\\\/\"},\"wordCount\":161,\"publisher\":{\"@id\":\"https:\\\/\\\/vielhuber.de\\\/#\\\/schema\\\/person\\\/64d4ff14713d413ea4d9b210d0c2c6ef\"},\"articleSection\":[\"Blog\"],\"inLanguage\":\"de\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/vielhuber.de\\\/blog\\\/git-status-2-0\\\/\",\"url\":\"https:\\\/\\\/vielhuber.de\\\/blog\\\/git-status-2-0\\\/\",\"name\":\"git status 2.0 &#060; Vielhuber David\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/vielhuber.de\\\/#website\"},\"datePublished\":\"2025-11-12T11:20:38+00:00\",\"dateModified\":\"2025-11-12T11:41:09+00:00\",\"description\":\"Wer morgens zuerst git status tippt und danach Kaffee trinkt, wird dieses kleine Helferlein lieben. Gerade wenn viele Webprojekte parallel entwickelt\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/vielhuber.de\\\/blog\\\/git-status-2-0\\\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/vielhuber.de\\\/blog\\\/git-status-2-0\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/vielhuber.de\\\/blog\\\/git-status-2-0\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/vielhuber.de\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"git status 2.0\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/vielhuber.de\\\/#website\",\"url\":\"https:\\\/\\\/vielhuber.de\\\/\",\"name\":\"Vielhuber David\",\"description\":\"Full-Stack Developer\",\"publisher\":{\"@id\":\"https:\\\/\\\/vielhuber.de\\\/#\\\/schema\\\/person\\\/64d4ff14713d413ea4d9b210d0c2c6ef\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/vielhuber.de\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"de\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/vielhuber.de\\\/#\\\/schema\\\/person\\\/64d4ff14713d413ea4d9b210d0c2c6ef\",\"name\":\"David\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"de\",\"@id\":\"https:\\\/\\\/vielhuber.de\\\/wp-content\\\/uploads\\\/about.jpg\",\"url\":\"https:\\\/\\\/vielhuber.de\\\/wp-content\\\/uploads\\\/about.jpg\",\"contentUrl\":\"https:\\\/\\\/vielhuber.de\\\/wp-content\\\/uploads\\\/about.jpg\",\"width\":700,\"height\":552,\"caption\":\"David\"},\"logo\":{\"@id\":\"https:\\\/\\\/vielhuber.de\\\/wp-content\\\/uploads\\\/about.jpg\"},\"sameAs\":[\"https:\\\/\\\/x.com\\\/vielhuber\"]}]}<\/script>","yoast_head_json":{"title":"git status 2.0 &#060; Vielhuber David","description":"Wer morgens zuerst git status tippt und danach Kaffee trinkt, wird dieses kleine Helferlein lieben. Gerade wenn viele Webprojekte parallel entwickelt","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/vielhuber.de\/blog\/git-status-2-0\/","og_locale":"de_DE","og_type":"article","og_title":"git status 2.0 &#060; Vielhuber David","og_description":"Wer morgens zuerst git status tippt und danach Kaffee trinkt, wird dieses kleine Helferlein lieben. Gerade wenn viele Webprojekte parallel entwickelt","og_url":"https:\/\/vielhuber.de\/blog\/git-status-2-0\/","og_site_name":"Vielhuber David","article_published_time":"2025-11-12T11:20:38+00:00","article_modified_time":"2025-11-12T11:41:09+00:00","og_image":[{"width":700,"height":552,"url":"https:\/\/vielhuber.de\/wp-content\/uploads\/about.jpg","type":"image\/jpeg"}],"author":"David","twitter_card":"summary_large_image","twitter_creator":"@vielhuber","twitter_site":"@vielhuber","twitter_misc":{"Verfasst von":"David","Gesch\u00e4tzte Lesezeit":"1\u00a0Minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/vielhuber.de\/blog\/git-status-2-0\/#article","isPartOf":{"@id":"https:\/\/vielhuber.de\/blog\/git-status-2-0\/"},"author":{"name":"David","@id":"https:\/\/vielhuber.de\/#\/schema\/person\/64d4ff14713d413ea4d9b210d0c2c6ef"},"headline":"git status 2.0","datePublished":"2025-11-12T11:20:38+00:00","dateModified":"2025-11-12T11:41:09+00:00","mainEntityOfPage":{"@id":"https:\/\/vielhuber.de\/blog\/git-status-2-0\/"},"wordCount":161,"publisher":{"@id":"https:\/\/vielhuber.de\/#\/schema\/person\/64d4ff14713d413ea4d9b210d0c2c6ef"},"articleSection":["Blog"],"inLanguage":"de"},{"@type":"WebPage","@id":"https:\/\/vielhuber.de\/blog\/git-status-2-0\/","url":"https:\/\/vielhuber.de\/blog\/git-status-2-0\/","name":"git status 2.0 &#060; Vielhuber David","isPartOf":{"@id":"https:\/\/vielhuber.de\/#website"},"datePublished":"2025-11-12T11:20:38+00:00","dateModified":"2025-11-12T11:41:09+00:00","description":"Wer morgens zuerst git status tippt und danach Kaffee trinkt, wird dieses kleine Helferlein lieben. Gerade wenn viele Webprojekte parallel entwickelt","breadcrumb":{"@id":"https:\/\/vielhuber.de\/blog\/git-status-2-0\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/vielhuber.de\/blog\/git-status-2-0\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/vielhuber.de\/blog\/git-status-2-0\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/vielhuber.de\/"},{"@type":"ListItem","position":2,"name":"git status 2.0"}]},{"@type":"WebSite","@id":"https:\/\/vielhuber.de\/#website","url":"https:\/\/vielhuber.de\/","name":"Vielhuber David","description":"Full-Stack Developer","publisher":{"@id":"https:\/\/vielhuber.de\/#\/schema\/person\/64d4ff14713d413ea4d9b210d0c2c6ef"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/vielhuber.de\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"de"},{"@type":["Person","Organization"],"@id":"https:\/\/vielhuber.de\/#\/schema\/person\/64d4ff14713d413ea4d9b210d0c2c6ef","name":"David","image":{"@type":"ImageObject","inLanguage":"de","@id":"https:\/\/vielhuber.de\/wp-content\/uploads\/about.jpg","url":"https:\/\/vielhuber.de\/wp-content\/uploads\/about.jpg","contentUrl":"https:\/\/vielhuber.de\/wp-content\/uploads\/about.jpg","width":700,"height":552,"caption":"David"},"logo":{"@id":"https:\/\/vielhuber.de\/wp-content\/uploads\/about.jpg"},"sameAs":["https:\/\/x.com\/vielhuber"]}]}},"_links":{"self":[{"href":"https:\/\/vielhuber.de\/zh-cn\/wp-json\/wp\/v2\/posts\/4551","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vielhuber.de\/zh-cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vielhuber.de\/zh-cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vielhuber.de\/zh-cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vielhuber.de\/zh-cn\/wp-json\/wp\/v2\/comments?post=4551"}],"version-history":[{"count":9,"href":"https:\/\/vielhuber.de\/zh-cn\/wp-json\/wp\/v2\/posts\/4551\/revisions"}],"predecessor-version":[{"id":4565,"href":"https:\/\/vielhuber.de\/zh-cn\/wp-json\/wp\/v2\/posts\/4551\/revisions\/4565"}],"wp:attachment":[{"href":"https:\/\/vielhuber.de\/zh-cn\/wp-json\/wp\/v2\/media?parent=4551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vielhuber.de\/zh-cn\/wp-json\/wp\/v2\/categories?post=4551"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vielhuber.de\/zh-cn\/wp-json\/wp\/v2\/tags?post=4551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}