<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>lp0fire.dev</title>
  <subtitle>A dev &amp; tech blog about software, systems, and the occasional fire.</subtitle>
  <link href="https://lp0fire.dev/feed.xml" rel="self" type="application/atom+xml"/>
  <link href="https://lp0fire.dev/" rel="alternate" type="text/html"/>
  <id>https://lp0fire.dev/</id>
  <updated>2026-11-18T16:06:21Z</updated>
  <author>
    <name>lp0fire.dev</name>
  </author>
  <icon>https://lp0fire.dev/favicon.svg</icon>

  <entry>
    <title>Stop looking up the last Git tag</title>
    <link href="https://lp0fire.dev/posts/git-new-patch/" rel="alternate" type="text/html"/>
    <id>https://lp0fire.dev/posts/git-new-patch/</id>
    <author>
      <name>EL_Greco</name>
    </author>
    <published>2026-11-18T15:41:08Z</published>
    <updated>2026-11-18T16:06:21Z</updated>
    <summary>Three Git aliases for creating the next patch, minor, or major tag without looking up the current version.</summary>
    <content type="html">&lt;p&gt;I want to tag a release. First, I have to look up the last version. Was it &lt;code&gt;1.4.2&lt;/code&gt; or &lt;code&gt;1.4.3&lt;/code&gt;? Then I copy the number, change one part, and hope I did not mistype it.&lt;/p&gt;
          &lt;p&gt;It is a tiny chore, but it comes up every time. I already know what I want: the next patch, minor, or major version. Git already has the tags. So I added three aliases:&lt;/p&gt;

          &lt;pre&gt;&lt;code&gt;git new-patch
git new-minor
git new-major&lt;/code&gt;&lt;/pre&gt;

          &lt;p&gt;Pick one. If the highest matching tag is &lt;code&gt;1.4.2&lt;/code&gt;, each command produces:&lt;/p&gt;

          &lt;table&gt;
            &lt;thead&gt;
              &lt;tr&gt;&lt;th scope="col"&gt;Command&lt;/th&gt;&lt;th scope="col"&gt;New tag&lt;/th&gt;&lt;/tr&gt;
            &lt;/thead&gt;
            &lt;tbody&gt;
              &lt;tr&gt;&lt;td&gt;&lt;code&gt;git new-patch&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;1.4.3&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
              &lt;tr&gt;&lt;td&gt;&lt;code&gt;git new-minor&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;1.5.0&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
              &lt;tr&gt;&lt;td&gt;&lt;code&gt;git new-major&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;2.0.0&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
            &lt;/tbody&gt;
          &lt;/table&gt;

          &lt;p&gt;Those are three alternatives starting from the same version. Running them one after another would keep advancing the version.&lt;/p&gt;

          &lt;h2&gt;Install once&lt;/h2&gt;
          &lt;p&gt;Paste this into a terminal running Bash or Zsh. It adds four entries to your global Git configuration: one helper and three short aliases. They are then available in all your repositories.&lt;/p&gt;

          &lt;pre data-copy&gt;&lt;code&gt;git config --global alias.semver-tag \
'!f() {
  level="$1"
  shift

  latest=$(
    git tag --list --sort=-version:refname |
      grep -E "^v?[0-9]+\.[0-9]+\.[0-9]+$" |
      head -n 1
  )

  if [ -n "$latest" ]; then
    prefix=""
    case "$latest" in
      v*) prefix=v ;;
    esac

    version=${latest#v}
    major=${version%%.*}
    rest=${version#*.}
    minor=${rest%%.*}
    patch=${rest#*.}
  else
    prefix=""
    major=0
    minor=0
    patch=0
  fi

  case "$level" in
    major)
      major=$((major + 1))
      minor=0
      patch=0
      ;;
    minor)
      minor=$((minor + 1))
      patch=0
      ;;
    patch)
      patch=$((patch + 1))
      ;;
    *)
      echo "usage: git semver-tag {major|minor|patch} [git tag options]" &amp;gt;&amp;amp;2
      return 2
      ;;
  esac

  next="${prefix}${major}.${minor}.${patch}"
  git tag "$@" "$next" &amp;amp;&amp;amp; echo "Created tag $next"
}; f'

git config --global alias.new-patch 'semver-tag patch'
git config --global alias.new-minor 'semver-tag minor'
git config --global alias.new-major 'semver-tag major'&lt;/code&gt;&lt;/pre&gt;

          &lt;h2&gt;What the helper does&lt;/h2&gt;
          &lt;p&gt;&lt;code&gt;semver-tag&lt;/code&gt; lists local tags using &lt;a href="https://git-scm.com/docs/git-tag"&gt;Git’s version sorting&lt;/a&gt;, highest first. That puts &lt;code&gt;1.10.0&lt;/code&gt; ahead of &lt;code&gt;1.9.0&lt;/code&gt;. It keeps tags shaped like &lt;code&gt;1.2.3&lt;/code&gt; or &lt;code&gt;v1.2.3&lt;/code&gt;, takes the first match, and increments the part you asked for. A minor bump resets the patch; a major bump resets both minor and patch.&lt;/p&gt;
          &lt;p&gt;If the selected tag starts with &lt;code&gt;v&lt;/code&gt;, the new one does too. If there are no matching tags, it starts from &lt;code&gt;0.0.0&lt;/code&gt;: the first patch is &lt;code&gt;0.0.1&lt;/code&gt;, the first minor is &lt;code&gt;0.1.0&lt;/code&gt;, and the first major is &lt;code&gt;1.0.0&lt;/code&gt;.&lt;/p&gt;
          &lt;p&gt;The &lt;code&gt;!f() { … }; f&lt;/code&gt; wrapper makes this a &lt;a href="https://git-scm.com/docs/git-config"&gt;shell command alias&lt;/a&gt;. The three shorter aliases call that helper with the bump level already filled in. &lt;code&gt;git new-patch&lt;/code&gt; is just &lt;code&gt;git semver-tag patch&lt;/code&gt;.&lt;/p&gt;

          &lt;h2&gt;Use it when the commit is ready&lt;/h2&gt;
          &lt;p&gt;The new tag points at &lt;code&gt;HEAD&lt;/code&gt;, your current commit. Commit the changes you want to release first. To make an annotated tag, pass the usual options through:&lt;/p&gt;

          &lt;pre&gt;&lt;code&gt;git new-patch -a -m "Fix the printer timeout"&lt;/code&gt;&lt;/pre&gt;

          &lt;p&gt;The helper prints the tag it created. Pushing that tag is a separate step. For example, if it prints &lt;code&gt;Created tag 1.4.3&lt;/code&gt;:&lt;/p&gt;

          &lt;pre&gt;&lt;code&gt;git push origin 1.4.3&lt;/code&gt;&lt;/pre&gt;

          &lt;p&gt;To push all local tags to &lt;code&gt;origin&lt;/code&gt; at once, you can also use:&lt;/p&gt;

          &lt;pre&gt;&lt;code&gt;git push origin --tags&lt;/code&gt;&lt;/pre&gt;

          &lt;p&gt;This includes any other local tags you have not pushed yet, not just the tag you created with the alias.&lt;/p&gt;

          &lt;h2&gt;A few boundaries&lt;/h2&gt;
          &lt;ul&gt;
            &lt;li&gt;&lt;strong&gt;It uses local tags.&lt;/strong&gt; If releases happen elsewhere, run &lt;code&gt;git fetch --tags&lt;/code&gt; first. It considers tags across the repository, including other branches, and chooses by version rather than creation date.&lt;/li&gt;
            &lt;li&gt;&lt;strong&gt;Keep the naming consistent.&lt;/strong&gt; Use either &lt;code&gt;v1.2.3&lt;/code&gt; or &lt;code&gt;1.2.3&lt;/code&gt; throughout a repository. Sorting includes the prefix, so mixing the two can select &lt;code&gt;v1.0.0&lt;/code&gt; ahead of &lt;code&gt;2.0.0&lt;/code&gt;.&lt;/li&gt;
            &lt;li&gt;&lt;strong&gt;It handles simple release numbers.&lt;/strong&gt; Tags such as &lt;code&gt;1.2.3-rc.1&lt;/code&gt;, &lt;code&gt;1.2.3+build.1&lt;/code&gt;, and &lt;code&gt;release-1.2.3&lt;/code&gt; are ignored. Use ordinary numeric components without leading zeroes.&lt;/li&gt;
            &lt;li&gt;&lt;strong&gt;You choose the bump.&lt;/strong&gt; The alias creates a tag; it does not inspect commits, change package versions, generate a changelog, or push anything.&lt;/li&gt;
          &lt;/ul&gt;

          &lt;p&gt;Now, when I want the next patch, I can type &lt;code&gt;git new-patch&lt;/code&gt; and let Git do the counting.&lt;/p&gt;</content>
  </entry>

  <entry>
    <title>hello!</title>
    <link href="https://lp0fire.dev/posts/hello/" rel="alternate" type="text/html"/>
    <id>https://lp0fire.dev/posts/hello/</id>
    <published>2026-11-17T00:00:00Z</published>
    <updated>2026-11-17T00:00:00Z</updated>
    <summary>lp0 is on fire. help!</summary>
    <content type="html">&lt;p&gt;lp0 is on fire. help!&lt;/p&gt;</content>
  </entry>
</feed>
