Skip to content

Add 'gh blame <path>' command to open blame view on GitHub #2296

@phil-blain

Description

@phil-blain

Describe the feature or problem you’d like to solve

It would be nice to be able to use gh to open the "Blame" view for a file on GitHub from the command line.

Proposed solution

Using git blame works fine to know who last changed some file, or some lines or some function within the file, but using it repetitively to understand how a piece of code evolved is a little bit cumbersome; you have to adjust the line numbers at each invocations (and possibly also the file name if the file was moved).

GitHub has a nice "Blame" view, and even better, a "View blame prior to this change" link at the left of each block of lines that were changed together, making it very easy to navigate the history of a given line range.

Additional context

Here is how it could work:

$ gh blame path/to/file
# opens https://github.com/$owner/$repo/blame/$current_branch/path/to/file
$ gh blame -L 202,210 path/to/file
# opens https://github.com/$owner/$repo/blame/$current_branch/path/to/file#L202-L210
$ gh blame $revision path/to/file
# opens https://github.com/$owner/$repo/blame/$revision/path/to/file

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementa request to improve CLI

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions