{"componentChunkName":"component---src-templates-post-js","path":"/blog/bash-script-before-reading-code","result":{"data":{"markdownRemark":{"html":"<p>I saw this awesome blog post <a href=\"https://piechowski.io/post/git-commands-before-reading-code/\">The Git Commands I Run Before Reading Any Code</a> detailing some git commands to help you navigate a new code base. Well, I decided to make a wrapper bash script around those commands.</p>\n<h2>The Script</h2>\n<p>Create a file <code>git-investigate</code> (no extension), mark it as executable (<code>chmod +x git-investigate</code>), and then add <code>git-investigate</code> to your <code>PATH</code>.</p>\n<p>This automatically registers the git subcommand <code>git investigate COMMAND</code>.</p>\n<deckgo-highlight-code language=\"bash\"  >\n          <code slot=\"code\">#!/usr/bin/env bash\n\n# A git subcommand for investigating a new code base\n#\n# Credit to https://piechowski.io/post/git-commands-before-reading-code/ for the original git commands\n\nset -euo pipefail\n\nFIRST_ARG=${1:-&quot;&quot;}\n\nlimit=${LIMIT:-20}\nsince=${SINCE:-1 year ago}\n\nechoerr() { printf &quot;%s\\n&quot; &quot;$*&quot; &gt;&amp;2; }\n\nif ! git rev-parse --is-inside-work-tree &gt;/dev/null 2&gt;&amp;1; then\n    echoerr &quot;Error: This is not a git repo: $PWD&quot;\n    exit 1\nfi\n\nif [ &quot;$FIRST_ARG&quot; = &quot;churn&quot; ]; then\n    echoerr &quot;A sorted list of most changed files in a given period of time&quot;\n    echoerr &quot;&quot;\n    echoerr &quot;Since: $since&quot;\n    echoerr &quot;Limit: $limit&quot;\n    echoerr &quot;&quot;\n    git log --format=format: --name-only --since=&quot;$since&quot; | sort | uniq -c | sort -nr | head -$limit\nelif [ &quot;$FIRST_ARG&quot; = &quot;contributors&quot; ]; then\n    git shortlog -sn --no-merges\nelif [ &quot;$FIRST_ARG&quot; = &quot;bugs&quot; ]; then\n    echoerr &quot;A sorted list of files with commits related to bugs or fixes&quot;\n    echoerr &quot;&quot;\n    echoerr &quot;Limit: $limit&quot;\n    echoerr &quot;&quot;\n    git log -i -E --grep=&quot;fix|bug|broken&quot; --name-only --format=&#39;&#39; | sort | uniq -c | sort -nr | head -$limit\nelif [ &quot;$FIRST_ARG&quot; = &quot;velocity&quot; ]; then\n    echoerr &quot;A sorted list of commit counts by month&quot;\n    echoerr &quot;&quot;\n     git log --format=&#39;%ad&#39; --date=format:&#39;%Y-%m&#39; | sort | uniq -c\nelif [ &quot;$FIRST_ARG&quot; = &quot;firefighting&quot; ]; then\n    echoerr &quot;A list commits relating to reverts, hotfixes, emergencies, or rollbacks&quot;\n    echoerr &quot;&quot;\n    echoerr &quot;Since: $since&quot;\n    echoerr &quot;&quot;\n     git log --oneline --since=&quot;$since&quot; | grep -iE &#39;revert|hotfix|emergency|rollback&#39;\nelif [ &quot;$FIRST_ARG&quot; = &quot;credit-to&quot; ]; then\n    echoerr &quot;Credit To:&quot;\n    echoerr &quot;&quot;\n    echo &quot;https://piechowski.io/post/git-commands-before-reading-code/&quot;\nelse\n    echo &quot;Usage: $0 {churn|contributors|bugs|velocity|firefighting|credit-to}&quot;\n    echo &quot;&quot;\n    echo &quot;Commands&quot;\n    echo &quot;&quot;\n    echo &quot;- churn: A sorted list of most changed files in a given period of time&quot;\n    echo &quot;- contributors: A sorted list of the most active committers&quot;\n    echo &quot;- bugs: A sorted list of files with commits related to bugs or fixes&quot;\n    echo &quot;- velocity: A sorted list of commit counts by month&quot;\n    echo &quot;- firefighting: A list commits relating to reverts, hotfixes, emergencies, or rollbacks&quot;\n    echo &quot;- credit-to: Link to the original blog post detailing these git commands&quot;\n    echo &quot;&quot;\n    echo &quot;Environment Variables&quot;\n    echo &quot;&quot;\n    echo &quot;LIMIT -- Limits the number of results in &#39;churn&#39; and &#39;bugs&#39;&quot;\n    echo &quot;SINCE -- Filters result by a natural time string e.g. 1 year ago in &#39;churn&#39; and &#39;firefighting&#39;&quot;\n    exit 1\nfi</code>\n        </deckgo-highlight-code>\n<h2>Usage</h2>\n<deckgo-highlight-code language=\"bash\"  >\n          <code slot=\"code\">cd myproject\n\ngit investigate\n\n# Usage: git-investigate {churn|contributors|bugs|velocity|firefighting|credit-to}\n#\n# Commands\n#\n# - churn: A sorted list of most changed files in a given period of time\n# - contributors: A sorted list of the most active committers\n# - bugs: A sorted list of files with commits related to bugs or fixes\n# - velocity: A sorted list of commit counts by month\n# - firefighting: A list commits relating to reverts, hotfixes, emergencies, or rollbacks\n# - credit-to: Link to the original blog post detailing these git commands\n#\n# Environment Variables\n#\n# LIMIT -- Limits the number of results in &#39;churn&#39; and &#39;bugs&#39;\n# SINCE -- Filters result by a natural time string e.g. 1 year ago in &#39;churn&#39; and &#39;firefighting&#39;\n\nSINCE=&#39;10 years ago&#39; LIMIT=10 git investigate churn\n\n# A sorted list of most changed files in a given period of time\n#\n#   75\n#   17 src/pages/about.js\n#   14 src/layouts/index.js\n#   11 src/pages/talks.js\n#   10 src/pages/projects.js\n#    7 src/html.js\n#    7 package-lock.json\n#    5 yarn.lock\n#    4 src/pages/training.js\n#    4 src/components/nav-menu.js\n\ngit investigate contributors\n\n# 70  Kylee Tilley\n#  2  dependabot[bot]\n\nLIMIT=10 git investigate bugs\n\n# A sorted list of files with commits related to bugs or fixes\n#\n#    7 src/pages/about.js\n#    4 src/layouts/index.js\n#    3 src/pages/talks.js\n#    1 src/pages/projects.js\n#    1 src/pages/index.js\n#    1 src/pages/blog.js\n#    1 src/components/nav-menu.js\n#    1 src/components/header.js\n#    1 package-lock.json\n#    1 gatsby-node.js\n\ngit investigate velocity\n\n# A sorted list of commit counts by month\n#\n#    1 2018-07\n#    2 2019-08\n#    7 2019-11\n#    3 2020-02\n#    2 2020-03\n#    1 2020-05\n#   15 2022-12\n#    4 2023-05\n#    1 2024-07\n#   40 2025-02\n\nSINCE=&#39;10 years ago&#39; git investigate firefighting\n\n# A list commits relating to reverts, hotfixes, emergencies, or rollbacks\n#\n# e60c355 Revert &quot;Upgrade npm dependencies&quot;\n\ngit investigate credit-to\n\n# Credit To:\n#\n# https://piechowski.io/post/git-commands-before-reading-code/</code>\n        </deckgo-highlight-code>","excerpt":"I saw this awesome blog post The Git Commands I Run Before Reading Any Code detailing some git commands to help you navigate a new code base…","frontmatter":{"date":"2026-06-19T00:00:00.000Z","title":"The Bash Script I Use Before Reading Any Code","tags":["git","tools","bash"]}},"site":{"siteMetadata":{"title":"Testing Required"}}},"pageContext":{"tags":["git","tools","bash"]}},"staticQueryHashes":["3649515864"]}