Bash script to list git commits by Linear ID

Posted . Visible to the public.

As we're switching from PT to Linear, I've updated the existing bash script to work for commits that are referencing Linear IDs.

A core benefit of our convention to prefix commits by their corresponding issue ID is that we can easily detect commits that belong to the same issue. You can either do that manually or use the bash script below. It can either be placed in your .bashrc or any location that is loaded by it.

# Usage: linearcommits FOO-123456
# Alternative usage: linearcommits
function linearcommits {
  if test "$1"
    local LINEAR_ID=$(echo "$1" | grep "[^/]*$" -o) # Extract linear ID from URLs
    git log --oneline --grep $LINEAR_ID | grep "^[a-z0-9]*" -o | xargs --no-run-if-empty git show $2 $3 $4
    echo "Please specify a Linear issue ID"

alias linearcommit='linearcommits'

Now you can use use the command with up to three arguments (just like a regular git show).
Example output for linearcommits ABC-165086636 --stat:

commit 048054b1df87576f7c59cc0161cc331c44d2ea6b
Author: Foo Bar <>
Date:   Fri Apr 5 14:24:24 2019 +0200

    [ABC-165086636] Linear issue Title

 app/assets/javascripts/test.js | 22 ++++++++++++++++++++++
 app/models/test.rb                    | 30 ++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 0 deletions(-)

See also

Michael Leimstädtner
Last edit
Michael Leimstädtner
Source code in this card is licensed under the MIT License.
Posted by Michael Leimstädtner to makandra dev (2024-06-17 09:04)